centos7下ftp伺服器的安裝和配置
1. 刪除firewalld防火牆
systemctl stop firewalld.service
yum remove firewalld.service
2.安裝iptables防火強
yum install iptables-services
systemctl start iptables.service
systemctl enable iptables.service
3.安裝vsftpd軟體
yum install vsftpd
systemctl start vsftpd.service
systemctl enable vsftpd.service
4.配置vsftpd vim /etc/vsftpd/vsftpd.conf
anonymous_enable=NO --禁用匿名登陸
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd/chroot_list --啟用vsftpd使用者
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
pasv_min_port=61001
pasv_max_port=62000
5. 在防火牆中開放埠 vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 21 -j ACCEPT --開放埠號21
-A INPUT -p TCP --dport 61001:62000 -j ACCEPT
-A OUTPUT -p TCP --sport 61001:62000 -j ACCEPT
重啟防火牆 systemctl restart iptables.service
6.配置selinux
通過 getsebool -a | grep ftp我們可以看到selinux是禁止了所有的ftp服務,為了能正常使用我們需要將
ftp_home_dir,ftpd_connection_db 兩個boolean變數設為true
setsebool -P ftp_home_dir 1setsebool -P ftpd_connect_db 1
或者修改selinux檔案註釋掉其它資訊增加SELINUX=disable
在執行setenforce 0 使得修改立即生效
7.增加ftp使用者
useradd -d /var/ftp -s /sbin/nologin ftpUser #######此處指定建立的ftp使用者訪問的根目錄
passwd ftpUser --為ftpUser這個使用者設定密碼
8.增加ftp使用者控制
在vsftpd的安裝目錄下增加chroot_list檔案 (每個使用者一行,該使用者將只能訪問/var/ftp下的目錄,在建立使用者時制定的)
所有加入該檔案的使用者將只能訪問建立使用者時指定的目錄
增加ftpUser這個使用者重啟vsftpd和iptables