查看ssh和防火牆的狀態
1 service sshd status
2 service iptables status
開啓ssh服務,關閉防火牆
1 service sshd startchkconfig iptables off
安裝並開啓tftp 和 vsftpd
1 yum update
2 yum install tftp
3 yum install vsftpd
4 chkconfig vsftpd on
5 chkconfig tftp on
6 service vsftpd start
查看ftp的啓動狀態
1 service vsftpd status
打開21和20的端口號:
1 /sbin/iptables -I INPUT -p tcp --dport 21 -j ACCEPT
2 /sbin/iptables -I INPUT -p tcp --dport 20 -j ACCEPT
3 /etc/rc.d/init.d/iptables save
添加ftp賬號,密碼和目錄
1 useradd -d /var/www/html -s /sbin/nologin ftpname
2 passwd ftpname
3 chown -R ftpname.ftpname/var/www/html
配置vsftpd配置文件
1 vim /etc/vsftpd/vsftpd.conf
2 禁止匿名登錄:anonymous_enable=NO
3 取消以下配置前的註釋符號:
4 local_enable=YES
5 write_enable=YES
6 chroot_local_user=NO
7 chroot_list_enable=NO
重啓vsftpd服務
1 service vsftpd restart
測試訪問ftp
C:UsersAdministrator>ftp 192.168.1.112
連接到 192.168.1.112。
220 (vsFTPd 2.2.2)
用戶(192.168.1.112:(none)): ftpuser
331 Please specify the password.
密碼:
500 OOPS: cannot change directory:/home/ftpuser
登錄失敗。
ftp> bye
可以看到報了個錯誤:500 OOPS: cannot change directory:/home/ftpuser。原因是CentOS系統安裝了SELinux,因爲默認下是沒有開啓FTP的支持,所以訪問時都被阻止了。查看如下:
[root@localhost vsftpd]# getsebool -a | grep ftp
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftp_home_dir --> off
ftpd_connect_db --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off
[root@localhost vsftpd]#
只要把allow_ftpd_full_access --> off,ftp_home_dir --> off改爲on就可以了。
1 setsebool ftp_home_dir 1
2 setsebool allow_ftpd_full_access 1
開啓SELinux
如執行getsebool -a | grep ftp出現getsebool: SELinux is disabled的錯誤,需重新開啓selinux
1 vi /etc/selinux/config
2 更改爲:SELINUX=enabled
3 必須重啓linux,不重啓是沒辦法立刻開啓selinux的
4 重啓完以後,就可以使用getsebool -a | grep ftp命令了