1.安装ftp服务
yum -y install vsftpd
2.添加登录名称和密码
添加用户名:useradd ftpuser
添加密码:passwd ftpuser 这里要注意,如果密码太简单会导致登录失败等问题
3.防火墙开启
-
外部访问ftp需要用到21端口、所以需要将21端口在防火墙里开放,因为我的服务器使用的是CentOS7系统、默认使用的是firewall防火墙,所以会有一些命令的变化
开启21端口:firewall-cmd --zone=public --add-port=21/tcp --permanent
重启firewall服务:systemctl restart firewall.service
-
如果使用的是CentOS7以下版本,就是操作iptables
开启21端口:vim /etc/sysconfig/iptables添加如下内容
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
重启iptables:service iptables restart
-
如果不想使用firewall可以执行 systemctl stop firewalld和systemctl disable firewalld
将firewall禁用,下载iptables
开启防火墙后正常来讲就可以使用ftp客户端访问服务器了,但是,又可能会出现获取不到目录的情况,这时就要查看selinux是否启动或者是否开启外网访问
-
输入命令查看selinux状态:getsebool -a | grep ftp
如果提示SELinux is disabled,代表SElinux被禁用了
执行命令:vim /etc/selinux/config 可以看到SELINUX=disabled,将disabled改为1;
wq保存后,重启Linux; -
如果没有错误信息,查看到allow_ftpd_full_access和ftp_home_dir都是off,代表没有开启外网访问
执行命令开启外网访问: setsebool -P allow_ftpd_full_access on
setsebool -P ftp_home_dir on
关闭匿名访问
vim /etc/vsftpd/vsftpd.conf 修改成下图;
重启ftp:systemctl restart vsftpd.service或者service vsftpd restart
设置开机启动ftp服务:chkconfig vsftpd on