How to setup FTP server (VSFTPD) – Ubuntu 14.04


FTP is used to transfer files from one host to another over TCP network. This article explains how to setup FTP server on ubuntu 14.04 .
There are 3 popular FTP server packages available PureFTPD, VsFTPD and ProFTPD.

In this particular example We will use VsFTPD which is lightweight and with less Vulnerabilities.

Setup FTP server on Ubuntu 14.04

Step 1 » Update repositories .
nextdime@dimebuntu:~$ sudo apt-get update

Step 2 » Install VsFTPD package using the below command.
nextdime@dimebuntu:~$ sudo apt-get install vsftpd

Step 3 » After installation open /etc/vsftpd.conf file and make changes as follows.
Uncomment the below lines (line no:29 and 33).
write_enable=YES
local_umask=022

Uncomment the below line (line no: 120 ) to prevent access to the other folders outside the Home directory.
chroot_local_user=YES

and add the following line at the end.
allow_writeable_chroot=YES

Add the following lines to enable passive mode.
pasv_enable=Yes
pasv_max_port=40000
pasv_min_port=40100

Step 4 » Restart vsftpd service using the below command.
nextdime@dimebuntu:~$ sudo service vsftpd restart

Step 5 » Now ftp server will listen on port 21. Create user with the below command.Use /usr/sbin/nologin shell to prevent access to the bash shell for the ftp users .
nextdime@dimebuntu:~$ sudo useradd -m john -s /usr/sbin/nologin
nextdime@dimebuntu:~$ sudo passwd john

Step 6 » Allow login access for nologin shell .

Open /etc/shells and add the following line at the end.
/usr/sbin/nologin

Now try to connect this ftp server with the username on port 21 using winscp orfilezilla client and make sure that user cannot access the other folders outside the home directory.
setup FTP server ubuntu 14.04
Please note using ftp on port 21 is a big security risk . it’s highly recommended to use SFTP. Please continue for SFTP configuration

Securing FTP ( SFTP )

SFTP is called as “Secure FTP” which generally use SSH File Transfer Protocol . so we need openssh-server package installed , Issue the below command if it’s not already installed.
nextdime@dimebuntu:~$ sudo apt-get install openssh-server

Step 7 » Again open /etc/vsftpd.conf file and add the below line to enable ssl.
ssl_enable=Yes

Step 8 » Create a new group ftpaccess for FTP users.
nextdime@dimebuntu:~$ sudo groupadd ftpaccess

Step 9 » Now make changes in this /etc/ssh/sshd_config file.
Find the below line
Subsystem sftp /usr/lib/openssh/sftp-server

and replace with
Subsystem sftp internal-sftp
Match group ftpaccess
ChrootDirectory %h
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp

and comment the below line ( Last line).
#UsePAM yes

Step 10 » Restart both VsFTPD and sshd service.
nextdime@dimebuntu:~$ sudo service vsftpd restart
nextdime@dimebuntu:~$ sudo service ssh restart

Step 11 » The below steps must be followed while creating Users for sftp access.
Create user john with ftpaccess group and /usr/bin/nologin shell.
nextdime@dimebuntu:~$ sudo useradd -m john -g ftpaccess -s /usr/sbin/nologin
nextdime@dimebuntu:~$ sudo passwd john
Change ownership for the home directory.
nextdime@dimebuntu:~$ sudo chown root /home/johnCreate a folder inside home directory for writing and change ownership for that folder.
nextdime@dimebuntu:~$ sudo mkdir /home/john/www
nextdime@dimebuntu:~$ sudo chown john:ftpaccess /home/john/www

Now try to connect server using SFTP ( port : 22 ) and makesure Users can upload files to www directory and cannot access other folders outside home directory.setup FTP server ubuntu 14.04

Good Luck!

About

“I am not what I ought to be, I am not what I want to be, I am not what I hope to be in another world; but still I am not what I once used to be, and by the grace of God I am what I am”

Tagged with: , , , , ,
Posted in Ubuntu

Leave a comment

Member of The Internet Defense League

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 516 other subscribers
Follow NextDime Networks on WordPress.com
My Community
Follow me on Twitter
Top Rated Posts
My Gravatar
nextdime

nextdime

“I am not what I ought to be, I am not what I want to be, I am not what I hope to be in another world; but still I am not what I once used to be, and by the grace of God I am what I am”

Verified Services

View Full Profile →