Centos 7 搭建ftp服务器-即安装vsftpd(20181113)

Centos 7 搭建ftp服务器-即安装vsftpd

 

 

* 安装vsftpd

步骤1:安装前检查是否已经安装vsftpd,使用yum安装

shell> vsftpd -v

shell> yum -y install vsftpd

 

步骤2:根据自己需求, 修改ftp配置文件/etc/vsftpd/vsftpd.conf

注意:每行配置末尾不能有空白字符

 

anonymous_enable=NO    # 是否允许匿名访问
local_enable=YES      # 是否允许使用本地帐户进行 FTP 用户登录验证
local_umask=022      # 设置本地用户默认文件掩码022
chroot_local_user=YES   # 是否限定用户在其主目录下(NO 表示允许切换到上级目录)#chroot_list_enable=YES # 是否启用限制用户的名单(注释掉为禁用)
chroot_list_file=/etc/vsftpd/chroot_list # 用户列表文件(一行一个用户)
allow_writeable_chroot=YES # 如果启用了限定用户在其主目录下需要添加这个配置,解决报错 500 OOPS: vsftpd: refusing to run with writable root inside chroot()
xferlog_enable=YES     # 启用上传和下载的日志功能,默认开启。
use_localtime=YES     # 是否使用本地时(自行添加)
userlist_enable=YES



chroot_local_user chroot_list_enable 的组合效果如下:

 

chroot_local_user=YES

chroot_local_user=NO

chroot_list_enable=YES

1. 所有用户都被限制在其主目录下
2. 使用 chroot_list_file 指定的用户列表,这些用户作为“例外”,不受限制

1. 所有用户都不被限制其主目录下
2. 使用 chroot_list_file 指定的用户列表,这些用户作为“例外”,受到限制

chroot_list_enable=NO

1. 所有用户都被限制在其主目录下
2. 不使用 chroot_list_file 指定的用户列表,没有任何“例外”用户

1. 所有用户都不被限制其主目录下
2. 不使用 chroot_list_file 指定的用户列表,没有任何“例外”用户


注意:如果设置了 local_enable=YES ,自带

 

* 启动 ftp 服务

修改 SELinux 配置

# 查看当前配置

shell> getsebool -a |grep ftp# 设置 ftp 可以访问 home 目录
shell> setsebool -P ftp_home_dir=1# 设置 ftp 用户可以有所有权限
shell> setsebool -P allow_ftpd_full_access=1

 

或者关闭 SELinux

shell> setenforce 0  

setenforce 0 设置SELinux 成为permissive模式 (关闭SELinux)
setenforce 1 设置SELinux 成为enforcing模式 (开启SELinux)

设置防火墙

# firewall-cmd --zone=public --permanent --add-port=21/tcp

# firewall-cmd --zone=public --permanent --add-port=20/tcp
# firewall-cmd --zone=public --permanent --add-service=ftp
# firewall-cmd --reload

 

启动 ftp 服务

shell> systemctl start vsftpd

注意:如果是腾讯云虚拟主机, 需要在安全组开通端口

用户管理

 # useradd -m -c “eva, PHP Developer” -s /bin/bash eva
# passwd eva

 

将用户名加入/etc/vsftpd/user_list文件中

 # echo "eva" | tee -a /etc/vsftpd.userlist
# cat /etc/vsftpd.userlist

 

* 主动模式与被动模式

ftp 的主动模式(Port 模式)与被动模式(PASV 模式)的区别:https://www.cnblogs.com/xiaohh/p/4789813.html
本文推荐使用被动模式vsftp 默认即为被动模式

  • 开启被动模式(PASV

/etc/vsftpd/vsftpd.conf 配置文件添加如下配置

pasv_enable=YES # 是否允许数据传输时使用PASV模式(默认值为 YES)
pasv_min_port=port port_number # PASV 模式下,数据传输使用的端口下界(0 表示任意。默认值为 0)把端口范围设在比较高的一段范围内,比如 50000-60000,将有助于安全性的提高.
pasv_max_port=port_number # PASV 模式下,数据传输使用的端口上界(0 表示任意。默认值为 0)
pasv_promiscuous=NO # 是否屏蔽对 PASV 进行安全检查,默认值为 NO(当有安全隧道时可禁用)
pasv_address # PASV 模式中服务器传回的 ip 地址。默认值为 none,即地址是从呼入的连接套接字中获取。

  • 开启主动模式(PORT)的配置

 port_enable=YES  # 是否开启 Port 模式
connect_from_port_20=YES # 当 Port 模式开启的时候,是否启用默认的 20 端口监听
ftp_data_port=port_number # Port 模式下 FTP 数据传输所使用的端口,默认值为20

 

* Configure Different FTP User Home Directories

  1. Open the vsftpd configuration file again and start by commenting the unsecure option below

#allow_writeable_chroot=YES

 

2.Then create the alternative local root directory for the user (eva, yours is probably different) and remove write permissions to all users to this directory:

 # mkdir /home/eva/ftp
# chown nobody:nobody /home/eva/ftp
# chmod a-w /home/eva/ftp

 

  1. Next, create a directory under the local root where the user will store his/her files:

# mkdir /home/ravi/ftp/files
# chown ravi:ravi  /home/ravi/ftp/files
# chmod 0700 /home/ravi/ftp/files/

 

3.Then add/modify the following options in the vsftpd config file with these values:

user_sub_token=$USER         # inserts the username in the local root directory
local_root=/home/$USER/ftp   # defines any users local root directory

$USER用eva代替

 

  1. Save the file and close it. Once again, let’s restart the service with the new settings:

# systemctl restart vsftpd

 

 

转载链接:

https://www.tecmint.com/install-ftp-server-in-centos-7/

https://www.jianshu.com/p/05dc6455b513

https://www.itzgeek.com/how-tos/linux/centos-how-tos/enable-passive-mode-in-ftp-on-centos-7-rhel-7-for-filezilla-and-winscp.html

 

posted @ 2018-11-13 16:18  饶翠  阅读(362)  评论(0编辑  收藏  举报