Tutorial
FTP has many uses, one of which is allowing numerous unknown users to download files. You have to be careful, because you run the risk of accidentally allowing unknown persons to upload files to your server. This sort of unintended activity can quickly fill up your hard drive with illegal software, images, and music for the world to download, which in turn can clog your server’s Internet access and drive up your bandwidth charges.
FTP Users with Read-Only Access to a Shared Directory
In this example, anonymous FTP is not desired, but a group of trusted users need to have read-only access to a directory for downloading files. Here are the steps:
- Disable anonymous FTP. Comment out the anonymous_enable line in
the vsftpd.conf file:
# Allow anonymous FTP? # anonymous_enable=YES
- Enable individual logins by making sure you have the
local_enable line uncommented in the vsftpd.conf
file:
# Uncomment this to allow local users to log in. local_enable=YES
- Start VSFTP.
[root@bigboy tmp]# service vsftpd start
- Create a user group and shared directory. In this case, use
/home/ftp-users and a user group name of ftp-users for the remote
users:
[root@bigboy tmp]# groupadd ftp-users [root@bigboy tmp]# mkdir /home/ftp-docs
- Make the directory accessible to the ftp-users group:
[root@bigboy tmp]# chmod 750 /home/ftp-docs [root@bigboy tmp]# chown root:ftp-users /home/ftp-docs
- Add users, and make their default directory
/home/ftp-docs:
[root@bigboy tmp]# useradd -g ftp-users -d /home/ftp-docs user1 [root@bigboy tmp]# useradd -g ftp-users -d /home/ftp-docs user2 [root@bigboy tmp]# useradd -g ftp-users -d /home/ftp-docs user3 [root@bigboy tmp]# useradd -g ftp-users -d /home/ftp-docs user4 [root@bigboy tmp]# passwd user1 [root@bigboy tmp]# passwd user2 [root@bigboy tmp]# passwd user3 [root@bigboy tmp]# passwd user4
Copy files to be downloaded by your users into the /home/ftp-docs directory.
- Change the permissions of the files in the /home/ftp-docs
directory to read-only access by the group:
[root@bigboy tmp]# chown root:ftp-users /home/ftp-docs/* [root@bigboy tmp]# chmod 740 /home/ftp-docs/*
- Users should now be able to log in via FTP to the server using their
new usernames and passwords. If you absolutely don’t want any FTP users to
be able to write to any directory, then you should set the write_enable
line in your vsftpd.conf file to no:
write_enable = NO
Remember, you must restart VSFTPD for the configuration file changes to take effect.
Sample Login Session to Test Functionality
Here is a simple test procedure you can use to make sure everything is working correctly:
- Check for the presence of a test file on the FTP client server.
[root@smallfry tmp]# ll total 1 -rw-r--r-- 1 root root 0 Jan 4 09:08 testfile [root@smallfry tmp]#
- Connect to Bigboy via
FTP:
[root@smallfry tmp]# ftp 192.168.1.100 Connected to 192.168.1.100 (192.168.1.100) 220 ready, dude (vsFTPd 1.1.0: beat me, break me) Name (192.168.1.100:root): user1 331 Please specify the password. Password: 230 Login successful. Have fun. Remote system type is UNIX. Using binary mode to transfer files. ftp>
As expected, you can’t do an upload transfer of testfile to bigboy:
ftp> put testfile local: testfile remote: testfile 227 Entering Passive Mode (192,168,1,100,181,210) 553 Could not create file. ftp>
- But we can view and download a copy of the VSFTPD RPM on the FTP server
bigboy:
ftp> ls 227 Entering Passive Mode (192,168,1,100,35,173) 150 Here comes the directory listing. -rwxr----- 1 0 502 76288 Jan 04 17:06 vsftpd-1.1.0-1.i386.rpm 226 Directory send OK. ftp> get vsftpd-1.1.0-1.i386.rpm vsftpd-1.1.0-1.i386.rpm.tmp local: vsftpd-1.1.0-1.i386.rpm.tmp remote: vsftpd-1.1.0-1.i386.rpm 227 Entering Passive Mode (192,168,1,100,44,156) 150 Opening BINARY mode data connection for vsftpd-1.1.0-1.i386.rpm (76288 bytes). 226 File send OK. 76288 bytes received in 0.499 secs (1.5e+02 Kbytes/sec) ftp> exit 221 Goodbye. [root@smallfry tmp]#
As expected, an anonymous FTP fails:
[root@smallfry tmp]# ftp 192.168.1.100 Connected to 192.168.1.100 (192.168.1.100) 220 ready, dude (vsFTPd 1.1.0: beat me, break me) Name (192.168.1.100:root): anonymous 331 Please specify the password. Password: 530 Login incorrect. Login failed. ftp> quit 221 Goodbye. [root@smallfry tmp]#
Now that testing is complete, you can make this a regular part of your FTP server’s operation.