CentOS7 builds FTP server

If you're experimenting in a virtual machine, it's a good idea to take a snapshot first to avoid restoring in case of error

 

1 . install vsftpd

#First check if you have vsftp installed

 [root@localhost /]# rpm -q vsftpd

vsftpd-3.0.2-10.el7.x86_64 (It shows that the installation is successful!)

#If not, install vsftpd

[root@localhost/]# yum  install -y  vsftpd

# check again when done

 [root@localhost /]# whereis  vsftpd

vsftpd:/usr/sbin/vsftpd /etc/vsftpd/usr/share/man/man8/vsftpd

 

#View the status of the vsftpd service

 [root@localhost /]# systemctl status vsftpd.service

(If it is active, there will be an active green mark)

#Activate vsftpd service

 [root@localhost /]# systemctl start vsftpd.service

#Set the vsftpd service to start automatically at boot

 [root@localhost /]#systemctl enable vsftpd.service

   

 

2. Configure vsftpd.conf

#First back up the configuration file (must be backed up to avoid recovery in the event of an accident.)

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

 

#Execute the following command (sed -i command is equivalent to directly modifying the original file)

sed -i "s/anonymous_enable=YES/anonymous_enable=NO/g" '/etc/vsftpd/vsftpd.conf'

 

sed -i "s/#anon_upload_enable=YES/anon_upload_enable=NO/g" '/etc/vsftpd/vsftpd.conf'

 

sed -i "s/#anon_mkdir_write_enable=YES/anon_mkdir_write_enable=YES/g" '/etc/vsftpd/vsftpd.conf'

 

sed -i "s/#chown_uploads=YES/chown_uploads=NO/g" '/etc/vsftpd/vsftpd.conf'

 

sed -i "s/#async_abor_enable=YES/async_abor_enable=YES/g" '/etc/vsftpd/vsftpd.conf'

 

sed -i "s/#ascii_upload_enable=YES/ascii_upload_enable=YES/g" '/etc/vsftpd/vsftpd.conf'

 

sed -i "s/#ascii_download_enable=YES/ascii_download_enable=YES/g" '/etc/vsftpd/vsftpd.conf'

 

sed -i "s/#ftpd_banner=Welcome to blah FTP service./ftpd_banner=Welcome toFTP service./g" '/etc/vsftpd/vsftpd.conf'

(Actually, you can also use

  vim /etc/vsftpd/vsftpd.conf Enter the configuration file and modify it as follows

    anonymous_enable=NO # Disable anonymous login

    ascii_upload_enable=YES

   ascii_download_enable=YES

   chroot_local_user=YES # Enable restricted users in their home directory

)

#Add the following to the end of vsftpd.conf after

use_localtime=YES

listen_port=21

chroot_local_user=YES

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=10060

pasv_max_port=10090

accept_timeout=5

connect_timeout=1

 

3. Create a user file

#The first line of user name, the second line of password, cannot use root as the user name

vim /etc/vsftpd/virtusers

add content

test

123456

liu

123456

 


4. Generate user data file

First you need to determine if you have the db_load command

rpm –q  db

Check before installing 

yum  search db4

Install

yum install-y compat-db47.x86_64 (depending on your machine) 

generate db file

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

 

#Set the PAM authentication file and specify to read the virtual user database file

chmod 600 /etc/vsftpd/virtusers.db (permission r,w)

 

 

 

5. Modify the /etc/pam.d/vsftpd file

# Backup before modifying

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

 

# Comment out all configuration lines for auth and account

vi /etc/pam.d/vsftpd

Add these two sentences inside

auth sufficient/lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers

 

account sufficient/lib64/security/pam_userdb.so db=/etc/vsftpd/virtusers

 

# If the system is 32-bit, the above lib64 is changed to lib

 


6. Create a new system user vsftpd , the user directory is /home/vsftpd

#Create a vsftpd folder in the home directory first, which is also the space we visit

mkdir -p /home/vsftpd

 

#User login terminal is set to /bin/ false (ie: make it impossible to log in to the system)

useradd vsftpd -d/home/vsftpd -s /bin/false

chown -R vsftpd:vsftpd /home/vsftpd

 


7. Create a virtual user personal profile

mkdir /etc/vsftpd/vconf

cd/etc/vsftpd/vconf

 

#Create two virtual user cooperation files here

touch test liu

 

#Create user root directory

mkdir -p /home/vsftpd/test/

 

#Edit the test user configuration file, the content is as follows, other users are similar

we test

 

local_root=/home/vsftpd/test/

write_enable=YES

anon_world_readable_only=NO

anon_upload_enable=YES

anon_mkdir_write_enable=YES

anon_other_write_enable=YES

 


8. Firewall settings ( centos 7 )

#If the system has firewall and SELinux enabled, the following configuration must be done (by default, centos7 uses firewall and selinux, not iptables)

 

#Firewall add FTP service:

[root@localhost vsftpd]#firewall-cmd --permanent --zone=public --add-service=ftp

[root@localhost vsftpd]#firewall-cmd --reload

#Set up SELinux :

[root@localhost vsftpd]#getsebool -a | grep ftp

[root@localhost vsftpd]#setsebool -P ftpd_full_access on

 

9. Restart the vsftpd server

[root@localhostchris]# systemctl stop  vsftpd.service

[root@localhostchris]# systemctl start  vsftpd.service

[root@localhostchris]# systemctl status  vsftpd.service

 

 

10. Test in several folders under /home/vsftpd/test/

mkdir  /home/vsftpd/test/test{1..5}

11. Enter ftp://192.168.163.126 ( LAN ) in the browser or my computer to test

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326124356&siteId=291194637
Recommended