FTP服務安裝
1. 查看操作系統(tǒng)版本
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
2. 安裝vsftp服務
[root@localhost ~]# yum install vsftpd -y
3. 創(chuàng)建一個系統(tǒng)用戶提供予虛擬用戶映射
[root@localhost ~]# useradd vsftpd -d /home/vsftpd -s /bin/nologin
# 查看創(chuàng)建的用戶和目錄
[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
如果用戶存在則執(zhí)行:
[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. 生成虛擬用戶數(shù)據(jù)文件
[root@localhost vsftpd]# vim /etc/vsftpd/vsftpd_login.txt
內(nèi)容如下(奇數(shù)行代表用戶名咖气,偶數(shù)行代表密碼):
zhangsan
123456
lisi
123456
wangwu
123456
這里配置了三個用戶:zhangsan, lisi, wangwu. 密碼都是:123456
然后執(zhí)行:
[root@localhost vsftpd]# db_load -T -t hash -f /etc/vsftpd/vsftpd_login.txt /etc/vsftpd/vsftpd_login.db
6. 配置PAM驗證文件(64位系統(tǒng))
執(zhí)行:vim /etc/pam.d/vsftpd 注釋掉原文件的內(nèi)容,輸入以下內(nèi)容:
[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. 創(chuàng)建用戶配置目錄
[root@localhost vsftpd]# mkdir -p /etc/vsftpd/vsftpd_user_conf/
[root@localhost vsftpd]# cd /etc/vsftpd/vsftpd_user_conf/
## 進入vsftpd_user_conf目錄蜘犁,創(chuàng)建與vsftpd_login.txt目錄配置的用戶名稱一樣的文件
## 當前配置的用戶為zhangsan狂鞋, 所以執(zhí)行: vi zhangsan
## 輸入以下內(nèi)容
## 需要注意 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. 創(chuàng)建數(shù)據(jù)目錄并賦權(quán)(重要)
[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 #查看運行狀態(tài)
10 . 測試