FTP服务安装
1. 查看操作系统版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
2. 安装vsftp服务
[root@localhost ~]# yum install vsftpd -y
3. 创建一个系统用户提供予虚拟用户映射
[root@localhost ~]# useradd vsftpd -d /home/vsftpd -s /bin/nologin
# 查看创建的用户和目录
[root@localhost ~]# ll /home/
total 0
drwxr-xr-x. 2 root root 6 Mar 23 16:21 big
drwx------. 3 bigdata bigdata 115 Mar 23 16:18 bigdata
drwx------. 3 bigdata user 78 Mar 22 10:12 user
drwxr-xr-x. 2 bigdata root 6 Mar 23 13:24 vsftpd
[root@localhost ~]# cat /etc/passwd |tail -n 1
vsftpd:x:1004:1005::/home/vsftpd:/bin/nologin
如果用户存在则执行:
[root@localhost ~]# usermod -s /sbin/nologin vsftpd
4. vsftpd.conf配置
[root@localhost ~]# cd /etc/vsftpd/
[root@localhost vsftpd]# vim vsftpd.conf
配置文件如下(需要注意win和unix的换行符差别):
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/xferlog
xferlog_std_format=YES
ascii_upload_enable=YES
ascii_download_enable=YES
ftpd_banner=This FTP is for the use of authorized users only. Individuals using this computer system without authority, or in excess of their authority, are subject to having all of their activities on this system monitored and recorded by system personnel, if such monitoring reveals possible evidence of criminal activity, system personnel may provide the evidence of such monitoring to law enforcement officials.
chroot_list_enable=NO
chroot_list_file=/etc/vsftpd/chroot_list
listen=YES
pasv_enable=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
reverse_lookup_enable=NO
guest_enable=YES
guest_username=vsftpd
user_config_dir=/etc/vsftpd/vsftpd_user_conf
dual_log_enable=YES
vsftpd_log_file=/var/log/vsftpd.log
use_localtime=YES
listen_port=10021
allow_writeable_chroot=YES
5. 生成虚拟用户数据文件
[root@localhost vsftpd]# vim /etc/vsftpd/vsftpd_login.txt
内容如下(奇数行代表用户名,偶数行代表密码):
zhangsan
123456
lisi
123456
wangwu
123456
这里配置了三个用户:zhangsan, lisi, wangwu. 密码都是:123456
然后执行:
[root@localhost vsftpd]# db_load -T -t hash -f /etc/vsftpd/vsftpd_login.txt /etc/vsftpd/vsftpd_login.db
6. 配置PAM验证文件(64位系统)
执行:vim /etc/pam.d/vsftpd 注释掉原文件的内容,输入以下内容:
[root@ck04 vsftpd]# vim /etc/pam.d/vsftpd
#%PAM-1.0
#session optional pam_keyinit.so force revoke
#auth required pam_listfile.so item=user sense=deny file=/etc/vsftpd/ftpusers onerr=succeed
#auth required pam_shells.so
#auth include password-auth
#account include password-auth
#session required pam_loginuid.so
#session include password-auth
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd_login
7. 创建用户配置目录
[root@localhost vsftpd]# mkdir -p /etc/vsftpd/vsftpd_user_conf/
[root@localhost vsftpd]# cd /etc/vsftpd/vsftpd_user_conf/
## 进入vsftpd_user_conf目录,创建与vsftpd_login.txt目录配置的用户名称一样的文件
## 当前配置的用户为zhangsan, 所以执行: vi zhangsan
## 输入以下内容
## 需要注意 local_root=/home/vsftpd/zhangsan
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
local_root=/home/vsftpd/zhangsan
ftpd_banner=This FTP is for the use of authorized users only
anon_other_write_enable=yes
## 其他用户同理配置即可
8. 创建数据目录并赋权(重要)
[root@localhost vsftpd]# mkdir -p /home/vsftpd/zhangsan
[root@localhost vsftpd]# mkdir -p /home/vsftpd/lisi
[root@localhost vsftpd]# mkdir -p /home/vsftpd/wangwu
[root@localhost vsftpd]# chown -R vsftpd:vsftpd /home/vsftpd/zhangsan
[root@localhost vsftpd]# chown -R vsftpd:vsftpd /home/vsftpd/lisi
[root@localhost vsftpd]# chown -R vsftpd:vsftpd /home/vsftpd/wangwu
9. 启动
[root@localhost vsftpd]# systemctl start vsftpd.service #启动
[root@localhost vsftpd]# systemctl restart vsftpd.service #重启
[root@localhost vsftpd]# systemctl status vsftpd.service #查看运行状态
10 . 测试