一、環境
一臺CentOS7.5服務器(搭建FTP文件傳輸服務)
192.168.10.178
二、匿名訪問
1、安裝vsftpd服務
yum -y install vsftpd
2、創建ftp訪問目錄並賦權
# 創建ftp目錄
mkdir -pv /ftp/test
# 給訪問目錄賦權
chown -R ftp.ftp /ftp
chmod a-w /ftp
ll -d /ftp
ll /ftp/test
3、修改配置文件
[root@localhost vsftpd]# cat vsftpd.conf
anonymous_enable=YES
local_enable=NO
write_enable=YES
local_umask=022
anon_umask=022
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
anon_root=/ftp
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
listen_ipv6=NO
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
allow_writeable_chroot=YES
4、重啓ftp服務
systemctl restart vsftpd
5、測試ftp
6、上傳下載
# 登錄ftp服務器(都是上傳下載到當前目錄)
get test
put test
三、用戶訪問
1、安裝vsftpd服務
yum -y install vsftpd
2、創建ftp訪問目錄並賦權
# 創建ftp目錄
mkdir /ftp
# 給目錄賦權
chown -R ftp.ftp /ftp/
# 查看ftp目錄權限
ll -d /ftp/
drwxrwxrwx 4 ftp ftp 56 Nov 28 02:33 /ftp/
3、修改配置文件
[root@localhost vsftpd]# cat vsftpd.conf |egrep -v "^$|^#"
anonymous_enable=NO
local_enable=YES
write_enable=YES
allow_writeable_chroot=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/xferlog
xferlog_std_format=YES
chroot_local_user=YES
listen_address=192.168.6.134
pam_service_name=vsftpd
local_root=/ftp
userlist_enable=YES
userlist_deny=NO
tcp_wrappers=YES
4、重啓ftp服務
systemctl restart vsftpd
5、測試登錄ftp
6、測試上傳下載
四、限制ftp用戶用指定IP地址訪問ftp服務器
1、修改/etc/pam.d/vsftpd配置文件
cat /etc/pam.d/vsftpd
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 system-auth
account required pam_access.so
account include system-auth
session include system-auth
session required pam_loginuid.so
2、修改/etc/security/access.conf配置文件
cat /etc/security/access.conf
-:test:ALL EXCEPT 10.39.63.10
# - 爲拒絕test用戶登錄 except爲除了10.39.63.10這個IP
# 意思爲允許10.39.63.10使用test用戶登錄
3、修改vsftpd.conf文件
# 監聽地址些詳細地址有可能會報錯
cat vsftpd.conf |egrep -v "^$|^#"
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_file=/var/log/xferlog
xferlog_std_format=YES
listen_address=192.168.6.134
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES