Centos 7 installation configuration vsftp service (virtual user login)

First, the experimental environment
OS: CentOS 7

Second, the installation

Close SELINUX:

vim /etc/selinux/config
SELINUX=disable

Temporary closure:

setenforce 0

Third, install vsftpd service:

1. Installation Installation yum vsftp:

yum -y install vsftp

2. Backup vsftp main configuration file:

cp /etc/vsftpd/vsftpd.conf{,.bak}

Fourth, configure user access to virtual vsftp services:

1. Create a virtual user password file:

user1
password1
user2
password2

2. Generate virtual user database:

yum -y install libdb-utils
db_load -T -t hash -f /etc/vsftpd/vir_user /etc/vsftpd/vir_user.db
chmod 700 /etc/vsftpd/vir_user.db

3. Verify the configuration file:

Before modifying the configuration file first

cp /etc/pam.d/vsftpd{,.bak}

The auth configuration line account and all are commented out, add the following two lines

vim /etc/pam.d/vsftpd

auth                 required     pam_userdb.so   db=/etc/vsftpd/vir_user 
account              required     pam_userdb.so   db=/etc/vsftpd/vir_user

4. Add a system user:

mkdir /ftproot
useradd -d /ftproot -s /sbin/nologin virftp
chown -R virftp:virftp /ftproot

5. Configuration vsftp master profile:

vim /etc/vsftpd/vsftpd.conf

# Prohibit anonymous user login

anonymous_enable=NO
#允许本地用户登录
local_enable=YES
#启用虚拟账户 
guest_enable=YES
#把虚拟账户映射到系统账户virftp               
guest_username=virftp
#使用虚拟用户验证(PAM验证)
pam_service_name=vsftpd
#设置存放各虚拟用户配置文件的目录(此目录下与虚拟用户名相同的文件为他的配置文件)
user_config_dir=/etc/vsftpd/vsftpd_viruser
#启用chroot时,虚拟用户根目录允许写入
allow_writeable_chroot=YES
  1. Configure each virtual user profiles:

Create a 'virtual user profile' storage directory

mkdir /etc/vsftpd/vsftpd_viruser/

Create and configure each virtual user configuration file, the file name is' virtual user name

vim /etc/vsftpd/vsftpd_viruser/user1

#允许写入
write_enable=YES
#允许浏览FTP目录和下载
anon_world_readable_only=NO
#允许虚拟用户上传文件
anon_upload_enable=YES
#允许虚拟用户创建目录
anon_mkdir_write_enable=YES
#允许虚拟用户执行其他操作(如改名、删除)
anon_other_write_enable=YES
#上传文件的掩码,如022时,上传目录权限为755,文件权限为644
anon_umask=022
#指定虚拟用户的虚拟目录(虚拟用户登录后的主目录)
local_root=/ftproot/admin/

Users create virtual root directory, to ensure that the system user virtual user mapping, has read and write access to the root directory

mkdir -p /ftproot/admin/
chown -R virftp.virftp /ftproot/admin/

Fifth, the test configuration:

1. Restart vsftpd service

systemctl restart vsftpd
systemctl enable vsftpd

2. Turn off the firewall:

setenforce 0
systemctl stop firewalld

3. Using FileZilla connection test tools

6. Each profile comments:

/etc/vsftpd/vsftpd.conf                             :vsftpd的主配置文件
/etc/vsftpd/vir_user                                   :虚拟用户的账号密码文件  
/etc/vsftpd/vsftpd_viruser/user1            :虚拟用户‘user1’的配置文件
/etc/pam.d/vsftpd                                     :启用虚拟用户验证功能的配置文件

Guess you like

Origin blog.51cto.com/14259167/2426873