阿里云cent6.8搭建ftp服务器

查看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命令了

猜你喜欢

转载自yq.aliyun.com/articles/656139