1、FTP的安装

centos 查询ftp用户_centos 查询ftp用户

#安装,使用vsftp
yum install -y vsftpd

#设置开机启动
systemctl enable vsftpd.service

#启动
systemctl start vsftpd.service 或 sudo service vsftpd start

#停止
systemctl stop vsftpd.service 或 sudo service vsftpd stop

#查看状态
systemctl status vsftpd.service 或 sudo service vsftpd status

centos 查询ftp用户_centos 查询ftp用户

 

2、配置FTP 

centos 查询ftp用户_centos 查询ftp用户

#打开配置文件
vim /etc/vsftpd/vsftpd.conf

#显示行号
:set number

#修改配置 12 行
anonymous_enable=NO

#修改配置 33 行
anon_mkdir_write_enable=YES

#修改配置48行
chown_uploads=YES

#修改配置72行
async_abor_enable=YES

#修改配置82行
ascii_upload_enable=YES

#修改配置83行
ascii_download_enable=YES

#修改配置86行
ftpd_banner=Welcome to blah FTP service.

#修改配置100行
chroot_local_user=YES

#添加下列内容到vsftpd.conf末尾
use_localtime=YES
listen_port=21
idle_session_timeout=300
guest_enable=YES
guest_username=vsftpd
user_config_dir=/etc/vsftpd/vconf
data_connection_timeout=1
virtual_use_local_privs=YES
pasv_min_port=40000
pasv_max_port=40010
accept_timeout=5
connect_timeout=1
allow_writeable_chroot=YES
或直接覆盖
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
anon_mkdir_write_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
chown_uploads=YES
xferlog_std_format=YES
async_abor_enable=YES
ascii_upload_enable=YES
ascii_download_enable=YES
ftpd_banner=Welcome to blah FTP service.
chroot_local_user=YES
listen=YES
listen_ipv6=NO
pam_service_name=vsftpd
userlist_enable=YES
use_localtime=YES
listen_port=21
idle_session_timeout=300
guest_enable=YES
guest_username=vsftpd
user_config_dir=/etc/vsftpd/vconf
data_connection_timeout=1
virtual_use_local_privs=YES
pasv_enable=YES
pasv_min_port=40000
pasv_max_port=41111
accept_timeout=5
connect_timeout=1
allow_writeable_chroot=YES

centos 查询ftp用户_centos 查询ftp用户

 

3、建立用户文件

centos 查询ftp用户_centos 查询ftp用户

#创建编辑用户文件
vim /etc/vsftpd/vuser
#第一行为用户名,第二行为密码。不能使用root作为用户名 

ftpuser
123456

centos 查询ftp用户_centos 查询ftp用户

 

4、生成用户数据文件

db_load -T -t hash -f /etc/vsftpd/vuser /etc/vsftpd/vuser.db

#设定PAM验证文件,并指定对虚拟用户数据库文件进行读取

chmod 600 /etc/vsftpd/vuser.db

 

5、修改 /etc/pam.d/vsftpd 文件

centos 查询ftp用户_centos 查询ftp用户

# 修改前先备份 

cp /etc/pam.d/vsftpd /etc/pam.d/vsftpd.bak

vi /etc/pam.d/vsftpd
#先将配置文件中原有的 auth 及 account 的所有配置行均注释掉
auth sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers 
account sufficient /lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers 

# 如果系统为32位,上面改为lib

centos 查询ftp用户_centos 查询ftp用户

 

6、新建系统用户vsftpd,用户目录为/home/vsftpd

#用户登录终端设为/bin/false(即:使之不能登录系统)
useradd vsftpd -d /home/vsftpd -s /bin/false
chown -R vsftpd:vsftpd /home/vsftpd

7、建立虚拟用户个人配置文件

centos 查询ftp用户_centos 查询ftp用户

mkdir /etc/vsftpd/vconf
cd /etc/vsftpd/vconf

#新建并编辑ftpuser用户配置文件,内容如下,其他用户类似
vi ftpuser

local_root=/home/vsftpd/leo/
write_enable=YES
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
#建立用户根目录
mkdir -p /home/vsftpd/ftpuser/
#授权,不然ftp连接后无法创建子目录及上传文件
chown vsftpd.vsftpd /home/vsftpd/ftpuser

centos 查询ftp用户_centos 查询ftp用户

 

8、防火墙设置

centos 查询ftp用户_centos 查询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-41111/tcp --permanent

centos 查询ftp用户_centos 查询ftp用户

 

9、重启vsftpd服务器

systemctl restart vsftpd.service

 

10、使用ftp工具连接测试

这个时候,使用ftp的工具连接时,我们发现是可以连接的。传输文件的时候,会发现文件上传和下载都会出现

500、503 、200等问题。这个时候,可以进行以下操作:

方式一、关闭SELINUX

centos 查询ftp用户_centos 查询ftp用户

#打开SELINUX配置文件
vim /etc/selinux/config


#修改配置参数
#注释  
SELINUX=enforcing

#增加  
SELINUX=disabled


#修改完成后,需要重启!

centos 查询ftp用户_centos 查询ftp用户

方式二、修改SELINUX

#列出ftp相关设置
getsebool -a|grep ftp


#以下是显示出来的权限,off是关闭权限,on是打开权限。不同的机器显示的可能不一样。我看了我的显示的,和网上其他教程就不太一样
ftp_home_dir --> off
ftpd_anon_write --> off
ftpd_connect_all_unreserved --> off
ftpd_connect_db --> off
ftpd_full_access --> off
ftpd_use_cifs --> off
ftpd_use_fusefs --> off
ftpd_use_nfs --> off
ftpd_use_passive_mode --> off
httpd_can_connect_ftp --> off
httpd_enable_ftp_server --> off
sftpd_anon_write --> off
sftpd_enable_homedirs --> off
sftpd_full_access --> off
sftpd_write_ssh_home --> off
tftp_anon_write --> off
tftp_home_dir --> off


#将包 ftpd_full_access 相关的都设置为 1

setsebool -P ftpd_full_access 1

方式三、 SELINUX不对vsftp不做任何限制

setsebool -P ftpd_connect_all_unreserved 1