Monday, October 10, 2011

Basic FTP Server Setup with vsftpd on Ubuntu

It’s pretty simple to install and to a basic configuration of an FTP server on Ubuntu. By default Ubuntu uses a package called vsftpd as an FTP server, which is currently the most popular FTP package for Linux systems. To install the vsftpd package, use the following command at the Terminal:

sudo apt-get install vsftpd

Follow the default prompts, and the vsftpd server will be installed on your computer. Generally, the default configuration for vsftpd is pretty secure, and good enough for casual use. Anonymous users are blocked, and no one can write files to the server (or, in FTP terminology, no one can upload files to the server). Anyone with a system account will be able to connect to the FTP server and download, though not upload, files.

If you want to change any settings, the configuration file for vsftpd is /etc/vsftpd.conf. Like any other configuration file, you can edit it with vi:

sudo vi /etc/vsftpd.conf

(If you’re using the desktop version of Ubuntu, you can of course use the graphical gedit editor.)

The vsftpd.conf file contains a large number of “directives” that govern how the server behaves and operates. If you want to change its configuration, you’ll need to alter the directives.

If you want users to be able to write files to your FTP server, change this directive:

#write_enable=YES

To this:

write_enable=YES

With the write_enable directive set to YES, users will be able to upload files to your FTP server. Note, however, that they will only be able to do so if they have proper permissions to the directories in question. They’ll be able to upload files to their home directories, but not, for instance /var or /usr.

Anonymous access is controlled with this directive:

anonymous_enable=NO

Under no circumstances should you allow anonymous access to your FTP server, especially if it is accessible from the Internet! There are certain circumstances when you might find it useful, but you should only enable it if you know exactly what you are doing. Generally, it is almost always best to keep anonymous_enable set to NO.

If you make any changes to the file, switch vi to command mode, save the changes, and then exit vi. Then restart the vsftpd server so it reads its new directives:

sudo service vsftpd restart

You can then test your Ubuntu machine’s FTP service from the server’s command line:

ftp 127.0.0.1

The FTP client will ask for your username. Enter that, and then the client will ask for your password. Enter that as well, and you should then see the FTP prompt, which looks like this:

ftp>

If you see that, you know the server is working. You can return to the regular command line with this command:

exit