Assume that we have the following requirements for path permission remarks/All ftp/open personnel, including guests, can access read-only/ftp/private, and only allow Alice, Jack, and Tom
Suppose we have the following requirements:
| Path |
Permission |
Remarks |
| /Ftp/open |
All staff of the company, including guests, can access |
Read-only |
| /Ftp/private |
Only Alice, Jack, and Tom are allowed to access |
Alice and Jack can only be downloaded, Tom can upload all files using a virtual account |
Install FTP
| |
// Use yum to install # yum-yinstall ftp vsftpd // or use rpm to install the following two packages of ftp-0.17-66.el7.x86_64vsftpd-3.0.2-9.el7.x86_64 // You also need to install the db package, used to encrypt the account information of the virtual user // This package has been installed by default in centos7 # rpm-qf/usr/bin/db_loadlibdb-utils-5.3.21-17.el7_0.1.x86_64 |
|
Configuration
| |
# Mkdir/ftp/open test files # echo opentest>/ftp/open/open.txt # echo filetest>/tmp/filetest1.txt # touch/ftp/open/anontest.txt // view the configuration file path # rpm-qc vsftpd/etc/logrotate. d/vsftpd/etc/pam. d/vsftpd/etc/vsftpd/ftpusers/etc/vsftpd/user_list/etc/vsftpd. conf # cd/etc/vsftpd // back up the original configuration file # cp vsftpd. conf vsftpd. conf. origin // create password plaintext file # vi/etc/vsftpd/vftpuser.txt aliceP @ ssw0rdjackP @ ssw0rdtomP @ ssw0rd // create password DB file # db_load-T-t hash-f/ etc/vsftpd/vftpuser.txt \/etc/vsftpd/vftpuser. db // view the password data file # file/etc/vsftpd/vftpuser. db/etc/vsftpd/vftpuser. db: Berkeley DB (Hash, version9, native byte-order) // Create a vftpd guest account # useradd-d/ftp/private-s/sbin/nologin vftpuser # vi/etc/pam. d/vsftpd comment out all the configuration line lines of auth and account and add the following content: auth required pam_userdb.so db =/etc/vsftpd/vftpuseraccount required pam_userdb.sodb =/etc/vsftpd/vftpuser // open the configuration file # vi/etc/vsftpd. conf // add anon_root =/ftp/openvirtual_use_local_privs = YESguest_enable = YESguest_username = enabled = YES // set automatic start # systemctl enable vsftpdln-s '/usr/lib/systemd /system/vsftpd. service ''/etc/systemd/system/multi-user.target.wants/vsftpd. service '# systemctlstart vsftpd // view the current status # systemctlstatus vsftpdvsftpd. service-Vsftpd ftp daemon Loaded: loaded (/usr/lib/systemd/system/vsftpd. service; enabled) Active: active (running) since Mon 19:57:12 CST; 22 h ago Main PID: 12733 (vsftpd) CGroup:/system. slice/vsftpd. service a "12733/usr/sbin/vsftpd/etc/vsftpd. conf systemd [1]: Starting Vsftpd ftp daemon... systemd [1]: Started Vsftpd ftp daemon. vsftpd [12738]: pam_userdb (vsftpd: auth): user 'Alice 'granted accessvsftpd [12753]: pam_userdb (vsftpd: auth): user 'Jack' granted accesssystemd [1]: started Vsftpd ftp daemon. |
|
Test
| |
// Test the anonymous account # ftplocalhostTrying: 1... connected to localhost (: 1 ). 220 (vsFTPd 3.0.2) Name (localhost: root): anonymous331 Please specify the password. password: 230 Login successful. remote system type is UNIX. using binary mode to transfer files. ftp> ls229 Entering Extended Passive Mode (||| 61057 | ). 150 Here comes the directory listing. -rw-r -- 1 0 0 9 Aug 11 open.txt 226 Directory send OK. ftp> LCD/t MpLocal directory now/tmpftp> getopen.txt local: open.txt remote: open.txt 229 Entering Extended Passive Mode (||| 64276 | ). 150 Opening BINARY mode data connection foropen.txt (9 bytes ). 226 Transfer complete.9 bytes encoded Ed in 0.000895 secs (10.06 Kbytes/sec) ftp> bye221 Goodbye. // test the local account # ftplocalhostTrying: 1... connected to localhost (: 1 ). 220 (vsFTPd 3.0.2) Name (localhost: root): alice331 Please spe Cify the password. password: 230 Login successful. remote system type is UNIX. using binary mode to transfer files. ftp> ls229 Entering Extended Passive Mode (||| 21750 | ). 150 Here comes the directory listing.226 Directory send OK. ftp>! Ls/tmpfiletest1.txt open.txt systemd-private-9xPN7y vmware-fonts0 vmware-installer1 vmware-root vmware-tools-distribks-script-_ Yi85R SAMBA.docx vmware-config0 vmware-installer0 vmware-installer2 vmware-root-2117481760 yum. logftp> LCD/tmpLocal directory now/tmpftp> putfiletest1.txtlocal: filetest1.txt remote: filetest1.txt229 Entering Extended Passive Mode (||| 65399 | ). 150 OK to send data.226 Transfer complete.9 bytes sent in 5.9e-05 secs (152.54 Kbytes/sec) ftp> bye221 Goodbye. |
|