zoukankan      html  css  js  c++  java
  • ubuntu12.04安装vsftp

    ubuntu安装配置FTP
     
    Ubuntu 12.04下安装FTP软件当然选择大名鼎鼎的vsftpd(very secure FTP daemon), Ubuntu装vsftpd很简单,一句命令就行:
     
    sudo apt-get install vsftpd
     
    命令执行过程中,安装程序会给本地创建一个名为“ftp”的用户组,命令执行完之后会自动启动FTP服务。
     
    可以使用“netstat -tl”命令检查FTP端口有没有已经打开,或者直接在浏览器里输入“ftp://你的服务器IP”(新安装的vsftpd默认是可以匿名不需要密码直接访问),如果能直接连接到FTP服务器,则安装vsftpd算是大功告成。
     
    开启、停止、重启vsftpd服务也很简单:
     
    service vsftpd start | stop | restart
     
    新安装的vsftpd默认是可以匿名访问,如果只想给某一个用户专门访问某一目录下的权限,则需要修改vsftpd的配置了。
     
    首先,创建一个专门用来访问的用户,例如叫“test”:
     
    mkdir -p /home/test
    sudo useradd -g ftp -d /home/test -M test
     
    PS: 删除用户用以下命令:
     
    sudo userdel test 
     
    设置密码:
     
    passwd test
     
    修改vsftpd的配置文件“vi /etc/vsftpd.conf”:
     
    #禁止匿名访问
    anonymous_enable=NO
    #接受本地用户
    local_enable=YES
    #可以上传
    write_enable=YES
    local_umask=022
    #启用在chroot_list_file的用户只能访问根目录
    chroot_list_enable=YES
    chroot_list_file=/etc/vsftpd.chroot_list
     
    在/etc/vsftpd.chroot_list添加受访问目录限制的用户:
     
    1.chroot_list_enable=YES (NO)
    是否启用 chroot 写入列表的功能?与底下的 chroot_list_flie 有关!这个项目得要开启,否则底下的列表档案会无效。 
    2.chroot_list_file=/etc/vsftpd.chroot_list
    如果 chroot_list_enable=YES 那麼就可以设定这个项目了
    3./etc/vsftpd/chroot_list
    这个档案预设是不存在的,所以你必须要手动自行建立。这个档案的主要功能是可以将某些帐号的使用者 chroot 在他们的家目录下!但这个档案要生效与 vsftpd.conf 内的『 chroot_list_enable, chroot_list_file 』两个参数有关。 如果你想要将某些实体用户限制在他们的家目录下而不许到其他目录去,可以启动这个设定项目喔!

    SO检查你的linux中是否有/etc/vsftpd/chroot_文件,如果没有,要自己建立
     
     
    “500 OOPS: vsftpd: refusing to run with writable root inside chroot()”
     
    启用了chroot的话,根目录要设置为不可写,这是vsftp的保护机制。
     
    chmod a-w /home/test
     
    那么用户登陆FTP就可以访问到test下的东西,但是没法去上传文件。如果把test文件夹设置成777权限,那么FTP就登陆不上去。
     
    所以解决办法是。在test文件夹下再创建一个文件夹“/home/test/wwwroot”,将wwwroot设置成777就可以了,那么以后上传东西就上传到wwwroot里。
     
    OK,重启vsftpd之后就可以使用上面新创建的账号访问。
     
    如果想改变ftp 默认登录的目录 则加入下面的命令
     
    /*
    #启用在chroot_list_file的用户只能访问根目录
    chroot_list_enable=YES
    chroot_list_file=/etc/vsftpd.chroot_list 这2个上面配置过了 是下面必须的前提
    */
     
    local_root=/usr/share/nginx/www         用户登录后的目录  这个可以注释掉不写 因为有 user_config_dir=/etc/vsftpd/userconf 这个下面对应的用户配置的路径
    chroot_local_user=NO                        这个一定要NO 否则可以访问上级目录
    #anon_root=/usr/share/nginx/www    这个是匿名用户登录后的目录 这里注释掉了 可以忽略

    user_config_dir=/etc/vsftpd/userconf  这个是分配每个用户的显示的目录 =号的右边 是配置文件的路径 如果有的话手动建立
     
    然后在userconf下 建立与用户名对应的配置文件 比如我这里是test用户 则 vim test
     
    里面输入 local_root=/usr/share/nginx/www 这里输入你需要例如test用户登录后的目录的路径
     
    配置完后 重启vsftpd 把连接ftp的工具或客户端 关掉 重新打开 应该就可以了
     
    下面是我自己的vsftp.conf里的内容
    -----------------------------------------------
    # Example config file /etc/vsftpd.conf
    #
    # The default compiled in settings are fairly paranoid. This sample file
    # loosens things up a bit, to make the ftp daemon more usable.
    # Please see vsftpd.conf.5 for all compiled in defaults.
    #
    # READ THIS: This example file is NOT an exhaustive list of vsftpd options.
    # Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
    # capabilities.
    #
    #
    # Run standalone?  vsftpd can run either from an inetd or as a standalone
    # daemon started from an initscript.
    listen=YES
    #
    # Run standalone with IPv6?
    # Like the listen parameter, except vsftpd will listen on an IPv6 socket
    # instead of an IPv4 one. This parameter and the listen parameter are mutually
    # exclusive.
    #listen_ipv6=YES
    #
    # Allow anonymous FTP? (Beware - allowed by default if you comment this out).
    anonymous_enable=NO
    #
    # Uncomment this to allow local users to log in.
    local_enable=YES
    #
    # Uncomment this to enable any form of FTP write command.
    write_enable=YES
    #
    # Default umask for local users is 077. You may wish to change this to 022,
    # if your users expect that (022 is used by most other ftpd's)
    local_umask=022
    #
    # Uncomment this to allow the anonymous FTP user to upload files. This only
    # has an effect if the above global write enable is activated. Also, you will
    # obviously need to create a directory writable by the FTP user.
    #anon_upload_enable=YES
    #
    # Uncomment this if you want the anonymous FTP user to be able to create
    # new directories.
    #anon_mkdir_write_enable=YES
    #
    # Activate directory messages - messages given to remote users when they
    # go into a certain directory.
    dirmessage_enable=YES
    #
    # If enabled, vsftpd will display directory listings with the time
    # in  your  local  time  zone.  The default is to display GMT. The
    # times returned by the MDTM FTP command are also affected by this
    # option.
    use_localtime=YES
    #
    # Activate logging of uploads/downloads.
    xferlog_enable=YES
    #
    # Make sure PORT transfer connections originate from port 20 (ftp-data).
    connect_from_port_20=YES
    #
    # If you want, you can arrange for uploaded anonymous files to be owned by
    # a different user. Note! Using "root" for uploaded files is not
    # recommended!
    #chown_uploads=YES
    #chown_username=whoever
    #
    # You may override where the log file goes if you like. The default is shown
    # below.
    #xferlog_file=/var/log/vsftpd.log
    #
    # If you want, you can have your log file in standard ftpd xferlog format.
    # Note that the default log file location is /var/log/xferlog in this case.
    #xferlog_std_format=YES
    #
    # You may change the default value for timing out an idle session.
    #idle_session_timeout=600
    #
    # You may change the default value for timing out a data connection.
    #data_connection_timeout=120
    #
    # It is recommended that you define on your system a unique user which the
    # ftp server can use as a totally isolated and unprivileged user.
    #nopriv_user=ftpsecure
    #
    # Enable this and the server will recognise asynchronous ABOR requests. Not
    # recommended for security (the code is non-trivial). Not enabling it,
    # however, may confuse older FTP clients.
    #async_abor_enable=YES
    #
    # By default the server will pretend to allow ASCII mode but in fact ignore
    # the request. Turn on the below options to have the server actually do ASCII
    # mangling on files when in ASCII mode.
    # Beware that on some FTP servers, ASCII support allows a denial of service
    # attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
    # predicted this attack and has always been safe, reporting the size of the
    # raw file.
    # ASCII mangling is a horrible feature of the protocol.
    #ascii_upload_enable=YES
    #ascii_download_enable=YES
    #
    # You may fully customise the login banner string:
    #ftpd_banner=Welcome to blah FTP service.
    #
    # You may specify a file of disallowed anonymous e-mail addresses. Apparently
    # useful for combatting certain DoS attacks.
    #deny_email_enable=YES
    # (default follows)
    #banned_email_file=/etc/vsftpd.banned_emails
    #
    # You may restrict local users to their home directories.  See the FAQ for
    # the possible risks in this before using chroot_local_user or
    # chroot_list_enable below.
    #chroot_local_user=YES
    #
    # You may specify an explicit list of local users to chroot() to their home
    # directory. If chroot_local_user is YES, then this list becomes a list of
    # users to NOT chroot().
    # (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
    # the user does not have write access to the top level directory within the
    # chroot)
    #chroot_local_user=YES
    chroot_list_enable=YES
    # (default follows)
    chroot_list_file=/etc/vsftpd.chroot_list
    #
    # You may activate the "-R" option to the builtin ls. This is disabled by
    # default to avoid remote users being able to cause excessive I/O on large
    # sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
    # the presence of the "-R" option, so there is a strong case for enabling it.
    #ls_recurse_enable=YES
    #
    # Customization
    #
    # Some of vsftpd's settings don't fit the filesystem layout by
    # default.
    #
    # This option should be the name of a directory which is empty.  Also, the
    # directory should not be writable by the ftp user. This directory is used
    # as a secure chroot() jail at times vsftpd does not require filesystem
    # access.
    secure_chroot_dir=/var/run/vsftpd/empty
    #
    # This string is the name of the PAM service vsftpd will use.
    pam_service_name=vsftpd
    #
    # This option specifies the location of the RSA certificate to use for SSL
    # encrypted connections.
    rsa_cert_file=/etc/ssl/private/vsftpd.pem

    #local_root =/usr/share/nginx/www/


    #local_root=/usr/share/nginx/www
    chroot_local_user=NO
    #anon_root=/usr/share/nginx/www

    user_config_dir=/etc/vsftpd/userconf
    -----------------------------------------------
    到此测试成功
     
    补充一个添加新用户的问题
     
    比如为ftp 添加新的用户test1
    mkdir -p /home/test1
    sudo useradd -g ftp -d /home/test1 -M test1
    passwd test1
     
    之后查看一下用户所属的组 查看test和test1 是否在ftp组里
    groups test test1 确定在同组后
    vim /etc/vsftpd.conf
    把 local_umask=000 这样 就可以test1和test 2个ftp用户 共同操作一个aa目录下的所有文件
    上传时也不会出现553错误了 也许还有更好的方法 这里我测试时是local_umask=000 不知道会不会有安全问题
     
    在/etc/vsftpd/userconf/下 建立一个test的配置 vim test1
    local_root=/usr/share/nginx/www 和test配置方法一样
    之后更改/usr/share/nginx/www/aa  这里比如aa是该项目的文件夹
    chown ftp:ftp aa  改权限为ftp组当然aa 也要有777的权限才行
    之后再上传的文件等 test和test1 都可以互相操作了
     
     
    ===========================
    下面是的是参考其他人的一些配置参数

    VSFTP用户目录指定

    1.修改VSFTP配置文件
     vi /etc/vsftpd/vsftp.conf

    #启动chroot列表
    chroot_list_enable=YES
    #指定列表位置
    chroot_list_file=/etc/vsftpd/chroot_list
    所有用户将被锁定在定义的目录

    userlist_enable=yes
    禁止文件/etc/vsftpd/user_list文件中的用户登陆FTP

    添加读取用户配置目录(注:本行配置默认没有需要手动输入)
    user_config_dir=/etc/vsftpd/userconf

     

    2.建立用户配置目录
     mkdir /etc/vsftpd/userconf

    3.建立用户登陆后的目录
     mkdir /export/home/nwom

    4.添加用户配置文件

    已知有用户nwom

    注:有很多用户时,需要建每个用户相对应的文件

     vi /etc/vsftpd/userconf/nwom

     local_root=/export/home/nwom

    FTP用户登陆后指定的目录

    5.重启VSFTP
    /etc/init.d/vsftpd restart

    登陆nwom用户FTP将登陆至/export/home/nwom目录

     
     
     
     
     
     
     
  • 相关阅读:
    cesium【02-小部件】
    cesium【01-初始化】
    【01】webpack4 快速上手
    【11】openlayers 地图交互
    【10】openlayers 视图view
    【09】openlayers 图片图层
    【08】openlayers 热力图层
    【07】openlayers 矢量图层
    测试从业人员常用的数据库技能整理
    基于web网站项目的性能测试结果分析
  • 原文地址:https://www.cnblogs.com/xiabaizhu/p/3906991.html
Copyright © 2011-2022 走看看