通过yum安装vsftpd 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 yum install vsftpd Is this ok [y/d/N]: y Downloading packages: vsftpd-3.0.2-22.el7.x86_64.rpm | 169 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction 正在安装 : vsftpd-3.0.2-22.el7.x86_64 1/1 验证中 : vsftpd-3.0.2-22.el7.x86_64 1/1 已安装: vsftpd.x86_64 0:3.0.2-22.el7 完毕!
新建一个上传文件夹 用于存放通过ftp上传的文件
1 2 3 4 pwd /usr/local mkdir ftpfile
新建一个ftp用户 新建ftpuser用户,该用户登录后的地址为/usr/local/ftpfile,这个用户不能登录系统
1 useradd ftpuser -d /ftpfile -s /sbin/nologin
修改/usr/local/ftpfile文件夹的权限 1 2 3 4 5 6 7 ll | grep ftpfile drwxr-xr-x 2 root root 6 6月 10 14:05 ftpfile chown -R ftpuser.ftpuser ftpfile/ ll | grep ftpfile drwxr-xr-x 2 ftpuser ftpuser 6 6月 10 14:05 ftpfile
为用户ftpuser添加密码
修改vsftpd配置文件 1 2 3 4 5 6 7 8 9 10 11 12 13 vi /etc/vsftpd/vsftpd.conf ftpd_banner=Welcome to simon's FTP service. local_root=/usr/local/ftpfile # 添加本地根目录 anon_root=/usr/local/ftpfile # use_localtime=yes chroot_list_enable=YES # 修改 # (default follows) chroot_list_file=/etc/vsftpd/chroot_list # 修改 anonymous_enable=NO
把用户ftpuser添加到/etc/vsftpd/chroot_list
1 vi /etc/vsftpd/chroot_list
添加一行记录,内容为:ftpuser
设置传输文件时的端口号 1 2 pasv_min_port=61001 pasv_max_port=62000
设置pasv被动传输的端口号,这样可以通过防火墙开放这个范围内的端口,从而更加安全。
启动vsftpd 1 2 service vsftpd start Redirecting to /bin/systemctl start vsftpd.service
测试 在浏览器上输入:ftp://192.168.1.30/ 输入用户名和密码后,貌似不能进去。
或者在终端输入
1 2 3 4 5 6 7 8 9 ftp 192.168.1.30 Connected to 192.168.1.30. 220 Welcome to simon's FTP service. Name (192.168.1.30:simon): ftpuser 331 Please specify the password. Password: 500 OOPS: vsftpd: refusing to run with writable root inside chroot() ftp: Login failed
会出现以上错误,所以还需要在配置文件里面加入如下参数:
1 allow_writeable_chroot=YES # 如果local_root是可写的就要设置这句
重启vsftpd服务后,再次登录,就成功了
1 2 3 4 5 6 7 8 9 10 ftp 192.168.1.30 Connected to 192.168.1.30. 220 Welcome to simon's FTP service. Name (192.168.1.30:simon): ftpuser 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp>
提示
默认为NO,表示用户能看到的最上层目录为/ftpfile。如果改为yes,那用户可以看到整个系统的目录结构。