阿里云CentOS7搭建任何网络服务,需要配置相应的安全组规则。
开启阿里云端口权限
阿里云服务器端口权限是由安全组规则控制,所以配置FTP服务,需要打开服务器的20/21端口权限。

由于需要FTP支持被动模式(PASV),所以还需要开启有限范围的端口权限比如(40000-40080)。

安装vsftpd
yum install -y vsftpd
修改vsftpd配置文件
vim /etc/vsftpd/vsftpd.conf
我的配置项如下:
anonymous_enable=NO #不允许匿名访问
local_enable=YES #允许使用本地帐户登录FTP
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
ascii_upload_enable=YES
ascii_download_enable=YES
chroot_local_user=YES #允许本地用户切换到FTP主目录以外的目录
chroot_list_enable=YES #白名单模式开启,只有/etc/vsftpd/chroot_list指定的用户才可以切换到主目录
chroot_list_file=/etc/vsftpd/chroot_list #本地用户切换目录白名单文件
listen=YES
listen_ipv6=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
local_root=/home/www/apache/html #FTP主目录
pasv_enable=YES #开启PASV模式
pasv_min_port=40000 #PASV最小端口
pasv_max_port=40080 #PASV最大端口
pasv_promiscuous=YES
allow_writeable_chroot=YES #允许写入目录(这项需要手动添加)
/etc/vsftpd/chroot_list文件如果不存在,创建一个空文件即可,否则无法开启FTP服务。
allow_writeable_chroot需要手动添加,否则FTP连接会报错。
配置防火墙
firewall-cmd --zone=public --add-service=ftp --permanent
firewall-cmd --zone=public --add-port=21/tcp --permanent
firewall-cmd --zone=public --add-port=40000-40080/tcp --permanent
systemctl restart firewalld.service
开启FTP服务
添加到开启启动
systemctl enable vsftpd.service
启动FTP服务
systemctl start vsftpd.service
其他命令
systemctl stop vsftpd.service #停止FTP服务
systemctl restart vsftpd.service #重启FTP服务
新建用于登录FTP的本地用户
useradd -d /www -g ftp -s /sbin/nologin ftpuser #新建用户名为ftpuser,不可用于系统登录
passwd ftpuser #修改密码
FileZilla测试登录
使用FileZilla登录FTP服务,配置如下:

登录成功,表示本地用户配置成功。

网友评论