Server 03 - Configure local yum+Vsftpd

Keywords: vsftpd yum SELinux vim

CentOS 6.5vsftpd-2.2.2-11 Installation (Virtual User)

==# The vsftpd service used is CentOS 6.5 with its own mirror==

Check to see if there is a mounted mirror CD

df -Th
Filesystem                   Type   Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root ext4    18G  3.4G   14G  21% /
tmpfs                        tmpfs  491M   72K  491M   1% /dev/shm
/dev/sda1                    ext4   485M   35M  426M   8% /boot

Create / mnt/cdrom CD mount directory and mount CD to that directory, prompting only read-only mount

mkdir /mnt/cdrom && mount /dev/cdrom /mnt/cdrom
mount: block device /dev/sr0 is write-protected, mounting read-only

Create a backup folder of yum configuration file to backup the original system yum configuration file

mkdir /etc/yum.back

Mobile yum.repos.d configuration file directory, all the original configuration files to the newly established Yum configuration file backup directory

cd /etc/yum.repos.d/ && mv * /etc/yum.back/

The yum configuration file for the new CD-ROM yum installation service is custom named cdyuminstall.repo

touch /etc/yum.repos.d/cdyuminstall.repo

Write the following configuration information in the configuration file

vim /etc/yum.repos.d/cdyuminstall.repo 
[cdinstall]
#Custom Naming
name=cdinstall
#Custom Naming
baseurl=file:///mnt/cdrom
#Custom path, which is the CD mount directory
enabled=1
#If yum source is enabled, 0 is not enabled, 1 is enabled
gpgcheck=0
#Whether to check GPG-KEY,0 is not checked, 1 is checked

yum cache with wq save and exit clearance after configuration

yum clean all

Install the vsftpd service on CD-ROM

yum install vsftpd

Waiting for the installation to complete to view the installed Service Information

rpm -q vsftpd
vsftpd-2.2.2-11.el6_4.1.x86_64

Back up the vsftpd configuration file to avoid irreversible configuration errors. Customize the backup name vsftpd.conf.bak

cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak

Import the backup configuration file vsftpd.conf.bak to the configuration file vsftpd.conf by removing blank lines and # beginning information

cd /etc/vsftpd
grep -vi "#" vsftpd.conf.bak | grep -vi ^$ > vsftpd.conf

View the exported configuration file information

[root@localhost vsftpd]# cat vsftpd.conf
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
[root@localhost vsftpd]#

Determine the db4 version of system integration

rpm -q db4
db4-4.7.25-18.el6_4.x86_64

Create custom named temporary text file and write virtual user name password

touch vusers.txt
[root@localhost vsftpd]# cat vusers.txt 
test
#Virtual User Account
test
#Virtual User Password

Load the newly created text into a custom named database virtual user

db_load -T -t hash -f vusers.txt vsftpd-virtual-user.db

Create pam authentication profile and specify database file path

vim /etc/pam.d/vsftpd.virtual
[root@localhost vsftpd]# cat /etc/pam.d/vsftpd.virtual 
auth required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd-virtual-user
account required /lib64/security/pam_userdb.so db=/etc/vsftpd/vsftpd-virtual-user
[root@localhost vsftpd]# 

Create a virtual user configuration directory for storing virtual user configuration information

mkdir -pv /etc/vsftpd/vhome

Create a virtual user host directory for virtual users to log in and access data

mkdir /usr/html

Allocate privileges to new virtual user test that has been built and imported into the database

vim /etc/vsftpd/vhome/test
[root@localhost vsftpd]# cat /etc/vsftpd/vhome/test 
anon_world_readable_only=NO
anon_upload_enable=YES
anon_mkdir_write_enable=YES
anon_other_write_enable=YES
anon_umask=033
local_root=/usr/html/

[root@localhost vsftpd]# 

Establish the system user web and assign directory permissions to him

useradd -s /sbin/nologin -c "web" web
chown -R web.web /usr/html

Directories must not be writable

chmod a-w /usr/html

Add virtual user configuration information to vsftpd.conf configuration file

[root@localhost vsftpd]# cat vsftpd.conf
anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
dual_log_enable=yes
#Increase Log Access Records
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
pam_service_name=vsftpd.virtual
userlist_enable=YES
tcp_wrappers=YES
#Modify the name of the pam authentication file. Do not use the default pam authentication profile. Here is the new configuration information.
guest_enable=YES
guest_username=web
user_config_dir=/etc/vsftpd/vhome

[root@localhost vsftpd]# 

Restart the corresponding service after modifying the configuration file information

[root@localhost vsftpd]# service vsftpd restart
 Turn off vsftpd:[OK]
Start vsftpd for vsftpd: [Determine]
[root@localhost vsftpd]#

Temporarily shut down SELinux mode, log in to virtual account will report an error, or permanently shut down the server needed to restart to write the vi/etc/sysconfig/selinux configuration file SELINUX=disabled. After writing the configuration file to restart, you can use getenforce to see the status of SELinux mode.

setenforce 0

# New directories and files under vsftp access directory for testing

mkdir /usr/html/test111 && touch /usr/html/222

Install the lftp service for access testing

yum -y install lftp

Attempt to log in to test with virtual users

[root@localhost vsftpd]# lftp 127.0.0.1
lftp 127.0.0.1:~> user test         
//Password: test
lftp test@127.0.0.1:~> ls
-rw-r--r--    1 500      500             0 Dec 01 06:56 222
drwxr-xr-x    2 0        0            4096 Dec 01 07:51 test111
lftp test@127.0.0.1:/> 

Posted by CrimsonSoul on Mon, 15 Jul 2019 11:02:25 -0700