📄 readme
字号:
This example shows how to set up vsftpd / PAM with "virtual users".A virtual user is a user login which does not exist as a real login on thesystem. Virtual users can therefore be more secure than real users, beacusea compromised account can only use the FTP server.Virtual users are often used to serve content that should be accessible tountrusted users, but not generally accessible to the public.Step 1) Create the virtual users database.We are going to use pam_userdb to authenticate the virtual users. This needsa username / password file in "db" format - a common database format.To create a "db" format file, first create a plain text files with theusernames and password on alternating lines.See example file "logins.txt" - this specifies "tom" with password "foo" and"fred" with password "bar".Whilst logged in as root, create the actual database file like this:db_load -T -t hash -f logins.txt /etc/vsftpd_login.db(Requires the Berkeley db program installed).NOTE: Many systems have multiple versions of "db" installed, so you mayneed to use e.g. db3_load for correct operation. This is known to affectsome Debian systems. The core issue is that pam_userdb expects its logindatabase to be a specific db version (often db3, whereas db4 may be installedon your system).This will create /etc/vsftpd_login.db. Obviously, you may want to make surethe permissions are restricted:chmod 600 /etc/vsftpd_login.dbFor more information on maintaing your login database, look around fordocumentation on "Berkeley DB", e.g.http://www.sleepycat.com/docs/utility/index.htmlStep 2) Create a PAM file which uses your new database.See the example file vsftpd.pam. It contains two lines:auth required /lib/security/pam_userdb.so db=/etc/vsftpd_loginaccount required /lib/security/pam_userdb.so db=/etc/vsftpd_loginThis tells PAM to authenticate users using our new database. Copy this PAMfile to the PAM directory - typically /etc/pam.d/cp vsftpd.pam /etc/pam.d/ftp(Note - if you set pam_service_name to e.g. vsftpd instead, you'll need to copyto /etc/pam.d/vsftpd).Step 3) Set up the location of the files for the virtual users.useradd -d /home/ftpsite virtualls -ld /home/ftpsite(which should give):drwx------ 3 virtual virtual 4096 Jul 30 00:39 /home/ftpsiteWe have created a user called "virtual" with a home directory "/home/ftpsite".Let's add some content to this download area:cp /etc/hosts /home/ftpsitechown virtual.virtual /home/ftpsite/hostsStep 4) Create your vsftpd.conf config file.See the example in this directory. Let's go through it line by line:anonymous_enable=NOlocal_enable=YESThis disables anonymous FTP for security, and enables non-anonymous FTP (whichis what virtual users use).write_enable=NOanon_upload_enable=NOanon_mkdir_write_enable=NOanon_other_write_enable=NOThese ensure that for security purposes, no write commands are allowed.chroot_local_user=YESThis makes sure that the virtual user is restricted to the virtual FTP area/home/ftpsite we set up above.guest_enable=YESguest_username=virtualThe guest_enable is very important - it activates virtual users! Andguest_username says that all virtual users are mapped to the real user"virtual" that we set up above. This will also determine where on thefilesystem the virtual users end up - the home directory of the user"virtual", /home/ftpsite.listen=YESlisten_port=10021This puts vsftpd in "standalone" mode - i.e. not running from an inetd. Thismeans you just run the vsftpd executable and it will start up. This alsomakes vsftpd listen for FTP requests on the non-standard port of 10021 (FTPis usually 21).pasv_min_port=30000pasv_max_port=30999These put a port range on passive FTP incoming requests - very useful ifyou are configuring a firewall.Copy the example vsftpd.conf file to /etc:cp vsftpd.conf /etc/Step 5) Start up vsftpd.Go to the directory with the vsftpd binary in it, and:./vsftpdIf all is well, the command will sit there. If all is not well, you willlikely see some error message.Step 6) Test.Launch another shell session (or background vsftpd with CTRL-Z and then "bg").Here is an example of an FTP session:ftp localhost 10021Connected to localhost (127.0.0.1).220 ready, dude (vsFTPd 1.1.0: beat me, break me)Name (localhost:chris): tom331 Please specify the password.Password:230 Login successful. Have fun.Remote system type is UNIX.Using binary mode to transfer files.ftp> pwd257 "/"ftp> ls227 Entering Passive Mode (127,0,0,1,117,135)150 Here comes the directory listing.226 Transfer done (but failed to open directory).ftp> size hosts213 147ftp>Comments:The password we gave was "foo".Do not be alarmed by the "failed to open directory". That is because thedirectory /home/ftpsite is not world readable (we could change thisbehaviour if we wanted using anon_world_readable_only=NO but maybe we wantit this way for security.We can see that we have access to the "hosts" file we copied into the virtualFTP area, via the size command.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -