阿里云cent6.8搭建ftp服务器
查看ssh和防火墙的状态
service sshd status
service iptables status
开启ssh服务,关闭防火墙
service sshd start
chkconfig iptables off
安装并开启tftp 和 vsftpd
yum update
yum install tftp
yum install vsftpd
chkconfig vsftpd on
chkconfig tftp on
service vsftpd start
查看ftp的启动状态
service vsftpd status
打开21和20的端口号:
/sbin/iptables -I INPUT -p tcp --dport 21 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 20 -j ACCEPT
/etc/rc.d/init.d/iptables save
添加ftp账号,密码和目录
useradd -d /var/www/html -s /sbin/nologin ftpname
passwd ftpname
chown -R ftpname.ftpname/var/www/html
配置vsftpd配置文件
vim /etc/vsftpd/vsftpd.conf
禁止匿名登录:anonymous_enable=NO
取消以下配置前的注释符号:
local_enable=YES
write_enable=YES
chroot_local_user=NO
chroot_list_enable=NO
重启vsftpd服务
service vsftpd restart
测试访问ftp
C:\Users\Administrator>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就可以了。
setsebool ftp_home_dir 1
setsebool allow_ftpd_full_access 1
开启SELinux
如执行getsebool -a | grep ftp出现getsebool: SELinux is disabled的错误,需重新开启selinux
vi /etc/selinux/config
更改为:SELINUX=enabled
必须重启linux,不重启是没办法立刻开启selinux的
重启完以后,就可以使用getsebool -a | grep ftp命令了
再次访问成功

浙公网安备 33010602011771号