Set up an FTP server

An FTP (File Transfer Protocol) server is a simple way of allowing users to exchange large files which are too big to send via email, and which can be accessed from virtually any web browser of FTP client. Multiple user accounts can be created on the same FTP server, and different permissions assigned to each user.

Install a base configuration of CentOS (http://www.centos.org), including the FTP and Web Server options. Strictly speaking the Web Server role is not required, but it is easier to add user accounts using Webmin than at the command line, which requires the web server role.

Once installed, start the web service using the following command:

service httpd start

Set the web service to launch automatically at startup:

chkconfig httpd on

Start the FTP server:

service vsftpd start

Set the FTP service to launch automatically at startup:

chkconfig vsftpd on

Download webmin from http://www.webmin.com/download.html

If you download the RPM installer package, issue the following command to install it:

rpm –i webmin-x.x.x.rpm

Create a directory on the server named ‘FTP’:

mkdir FTP

change to that directory:

cd FTP

create directories for logins as required:

mkdir Sales
mkdir Technical
mkdir Marketing

Log into webmin from a web browser:

http://(ftp_server):10000

Log in as root. Browse to System → Users and Groups
Create a new user account using the desired username
Set the Home Directory to the /FTP/xxx directory you created earlier
Assign a suitable password to the user account
Set the ‘Shell’ to /sbin/nologin
Set the Primary Group to ‘FTP'
Save the new user account

Repeat for the other user accounts as required (sales, marketing and technical in this example)

Return to the command prompt.
Set the ‘owner’ of the target FTP folders with the ‘chown’ command:

chown –R sales /FTP/Sales
chown –R marketing /FTP/Marketing
chown –R technical /FTP/Technical

(the –R switch makes the chown command apply to subdirectories of the parent)

Now edit the properties of the vsftpd.conf configuration file:

view /etc/vsftpd/vsftpd.conf

Make the following changes to the default configuration:

anonymous_enable=NO
local_enable=YES
write_enable=YES
anon_upload_enable=NO

Add a new line at the end of the file:

chroot_local_user=YES

Save the new file.

Restart the FTP service:

service vsftpd restart

At this point your FTP server is now available. Your router and/or firewall will need to be configured to allow FTP access to the machine (TCP port 21).

When connecting to the server you will be prompted for a username and password. Logging in as the ‘sales’ user will take you to the /FTP/Sales directory, logging in as the ‘marketing’ user will take you to the /FTP/Marketing directory and so on.

Should you want different logins to take you to the same folder, but with different permissions, then use the ‘chmod’ command on the folder.

For example, let’s say you need the same folder to be accessible to 2 users: ‘ftpreadaccess’ and ‘ftpwriteaccess’ with the corresponding permissions.

Create the required user accounts and set the home directory for both to the same folder.

Use the ‘chown’ command to set the owner of the folder to the ‘ftpwriteaccess’ user

Now use the chmod command to set the permissions:

chmod 755 folder

(where folder is the directory)

This will set the permissions of the folder to:

Owner – read, write and access
Group – read and access (in this case 'FTP' members)
Other – read and access

The easiest way to work out permissions is via your FTP client: connect as the owner user, or root, and edit the properties of the folder:

Setting Permissions

Your FTP site is now set up and ready to go.