RHCE tutorial-ftp virtual account

Source: Internet
Author: User
Thisexampleshowshowtosetupvsftpd/PAMwith "virtualusers". Avirtualuserisauserloginwhichdoesnotexistasarealloginonthesystem. Virtualuserscanthereforebemoresecurethanre

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
System. Virtual users can therefore be more secure than real users, beacuse
A compromised account can only use the FTP server.

Virtual users are often used to serve content that shoshould be accessible
Untrusted 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 needs
A username/password file in "db" format-a common database format.
To create a "db" format file, first create a plain text files with
Usernames and password on alternating lines.
See example file "logins.txt"-this specifies "tom" with password "foo" and
"Fred" with password "bar ".

Vim logins.txt

RedHat100

Passwd

Redhat200

Passwd
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: operating systems have multiple versions of "db" installed, so you may
Need to use e.g. db3_load for correct operation. This is known to affect
Some Debian systems. The core issue is that pam_userdb expects its login
Database to be a specific db version (often db3, whereas db4 may be installed
On your system ).

This will create/etc/vsftpd/login. db. obviusly, you may want to make sure
The permissions are restricted:

Chmod 600/etc/vsftpd/login. db

For more information on maintaing your login database, look around
Documentation on "Berkeley DB", e.g.
Step 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/login
Account required/lib/security/pam_userdb.so db =/etc/vsftpd/login

This tells PAM to authenticate users using our new database. Copy this PAM
File 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 copy
To/etc/pam. d/vsftpd ).


Step 3) Set up the location of the files for the virtual users.

Useradd-d/home/ftpsite virtual
Ls-ld/home/ftpsite
(Which shoshould give ):
Drwx ------  3 virtualVirtual    4096 Jul 30/home/ftpsite

We 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/ftpsite
Chown virtual. virtual/home/ftpsite/hosts


Step 4) Create your vsftpd. conf config file.

See the example in this directory. Let's go through it line by line:

Anonymous_enable = NO
Local_enable = YES

This disables anonymous FTP for security, and enables non-anonymous FTP (which
Is what virtual users use ).

Write_enable = NO
Anon_upload_enable = NO
Anon_mkdir_write_enable = NO
Anon_other_write_enable = NO

These ensure that for security purposes, no write commands are allowed.

Chroot_local_user = YES

This makes sure that the virtual user is restricted to the virtual FTP area
/Home/ftpsite we set up abve.

Guest_enable = YES
Guest_username = virtual

The guest_enable is very important-it activates virtual users! And
Guest_username says that all virtual users are mapped to the real user
"Virtual" that we set up above. This will also determine where on
Filesystem the virtual users end up-the home directory of the user
"Virtual",/home/ftpsite.

Listen = YES
Listen_port= 10021

This puts vsftpd in "standalone" mode-I. e. not running from an inetd. This
Means you just run the vsftpd executable and it will start up. This also
Makes vsftpd listen for FTP requests on the non-standard port of 10021 (FTP
Is usually 21 ).

Pasv_min_port = 30000
Pasvanderbilt max_port = 30999

These put a port range on passive FTP incoming requests-very useful if
You are running ing a firewall.

Copy the example vsftpd. conf file to/etc/vsftpd:

Cp vsftpd. conf/etc/vsftpd/


Step 5) Start up vsftpd.

Go to the directory with the vsftpd binary in it, and:

./Vsftpd

If all is well, the command will sit there. If all is not well, you will
Likely 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 10021
Connected to localhost (127.0.0.1 ).
220 ready, dude (vsFTPd 1.1.0: beat me, break me)
Name (localhost: chris): tom
331 Please specify the password.
Password:
230 Login successful. Have fun.
Remote system type is UNIX.
Using binary mode to transfer files.
Ftp> pwd
257 usd "/"
Ftp> ls
227 Entering Passive Mode (117,135, 0)
150 Here comes the directory listing.
226 Transfer done (but failed to open directory ).
Ftp> size hosts
213 147
Ftp>

Comments:
The password we gave was "foo ".
Do not be alarmed by the "failed to open directory". That is because
Directory/home/ftpsite is not world readable (we cocould change this
Behaviour if we wanted using anon_world_readable_only = NO but maybe we want
It this way for security.
We can see that we have access to the "hosts" file we copied into the virtual
FTP area, via the size command.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.