centos7.5 x86_64
yum install -y vsftpd
建立Vsftpd虚拟宿主用户:
useradd vsftpd -s /sbin/nologin修改配置文件
cd /etc/vsftpd/ && cp vsftpd.conf{,.bak}vi /etc/vsftpd/vsftpd.conf
# Example config file /etc/vsftpd/vsftpd.conf # # Allow anonymous FTP? (Beware - allowed by default if you comment this out). anonymous_enable=NO 不允许匿名访问 # # Uncomment this to allow local users to log in. # When SELinux is enforcing check for SE bool ftp_home_dir 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. # When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access #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 # # Activate logging of uploads/downloads. xferlog_enable=YES 开启上传下载日志 # # Make sure PORT transfer connections originate from port 20 (ftp-data). connect_from_port_20=YES 20端口进行数据传输 # # 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/xferlog 上传下载日志记录文件 # # 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=ftp 用系统自带的ftp用户作为vsftpd服务宿主用户,服务相关的文件权限应修改为本用户 # # 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 支持ASCII模式的上传和下载功能 # # 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 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 # # When "listen" directive is enabled, vsftpd runs in standalone mode and # listens on IPv4 sockets. This directive cannot be used in conjunction # with the listen_ipv6 directive. listen=YES 开启侦听 # # This directive enables listening on IPv6 sockets. By default, listening # on the IPv6 "any" address (::) will accept connections from both IPv6 # and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6 # sockets. If you want that (perhaps because you want to listen on specific # addresses) then you must run two copies of vsftpd with two configuration # files. # Make sure, that one of the listen options is commented !! #listen_ipv6=YES 关闭IPv6 pam_service_name=vsftpd #启用pam认证 userlist_enable=YES #userlist_file的用户不能登录FTP tcp_wrappers=YES开启虚拟用户
guest_enable=YES 指定虚拟用户宿主 guest_username=vsftpd 虚拟用户有宿主用户一样的权限 virtual_use_local_privs=YES 虚拟用户个人配置文件的存放路径,可个性定制权限 user_config_dir=/etc/vsftpd/vconf建立vsftpd的上传下载日志文件
touch /var/log/xferlog chown ftp.ftp /var/log/xferlog 建立虚拟用户配置文件目录 mkdir /etc/vsftpd/vconf/ 建虚拟用户文件,格式:“一行用户名,一行口令” touch /etc/vsftpd/vusers vi /etc/vsftpd/vusers user01 12345678 user02 12345678 生成虚拟用户数据文件 db_load -T -t hash -f /etc/vsftpd/vusers /etc/vsftpd/vusers.db新增虚拟用户时,仍需再次执行该命令才生效
设定PAM验证文件,并指定虚拟用户数据库文件进行读取
cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bk vi /etc/pam.d/vsftpd 注释掉原文后添加以下下内容(不注释掉所有原文,虚拟用户会登录不上) auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vusers account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vusers定制虚拟用户模板配置文件
vi /etc/vsftpd/vconf/vconf.tmp local_root=/var/ftp/vuser #不指定用户名虚拟用户登录后根目录是/home/vsftpd #指定虚拟用户的具体主路径。 anonymous_enable=NO #设定不允许匿名用户访问。 write_enable=YES #设定允许写操作。 local_umask=022 #设定上传文件权限掩码。 anon_upload_enable=NO #设定不允许匿名用户上传。 anon_mkdir_write_enable=NO #设定不允许匿名用户建立目录。 idle_session_timeout=600 #设定空闲连接超时时间。 data_connection_timeout=120 #设定单次连续传输最大时间。 max_clients=10 #设定并发客户端访问个数。 max_per_ip=5 #设定单个客户端的最大线程数,这个配置主要来照顾Flashget、迅雷等多线程下载软件。 download_enable=YES #可下载,不准改为NO local_max_rate=50000 #设定该用户的最大传输速率,单位b/s。cp vconf.tmp user01
用户拥有上传,下载,新建,删除权限 anon_upload_enable=YES anon_mkdir_write_enable=YES anon_other_write_enable=YES 用户只拥有上传,下载,新建权限,不允许删除操作 anon_upload_enable=YES anon_mkdir_write_enable=YES anon_other_write_enable=NO建立用户登录后的目录
cd /var/ftp/ mkdir user{01..02} chown -R vsftpd.vsftpd /var/ftp/启动vsftpd服务
systemctl start vsftpd systemctl status vsftpd