How to install and configure FTP server in Ubuntu 12.04 LTS

How to install and configure FTP server in Ubuntu 12.04 LTS

Target Readers: Linux new users or linux system admins
FTP Server IP Address = 10.10.0.25

This post has second part also: Read later if you do not know how anonymous user can login in FTP server. Given below is second part of this post
How to install and configure Secure FTP server in Ubuntu 12.04 LTS

In this tutorial we will learn how to install and configure vsftpd server in Ubuntu 12.04 LTS
In this post we will configure the FTP server for anonymous user only.
In upcoming post I will show some more advanced and secure FTP server configuration.

Note: We will install the vsftpd 3.0 package after downloading it into the system. We are not going to use “apt-get install” method . The reason it has bug related to chroot enable.For reference https://sharadchhetri.com/2013/05/20/500-oops-vsftpd-refusing-to-run-with-writable-root-inside-chroot/

Follow the given below steps

Step 1: login into system and become superuser root

sudo su – or su –

Step2 : Download vsftpd package and install it

tux@ubuntu:~$ sudo su –
[sudo] password for tux:
root@ubuntu:~#
root@ubuntu:~# cd /root/
root@ubuntu:~# wget http://security.ubuntu.com/ubuntu/pool/main/v/vsftpd/vsftpd_3.0.2-1ubuntu2_i386.deb
–2013-05-20 09:36:20– http://security.ubuntu.com/ubuntu/pool/main/v/vsftpd/vsftpd_3.0.2-1ubuntu2_i386.deb
Resolving security.ubuntu.com (security.ubuntu.com)… 91.189.92.190
, 91.189.92.201, 91.189.92.202, …
Connecting to security.ubuntu.com (security.ubuntu.com)|91.189.92.190|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 114714 (112K) [application/x-debian-package]
Saving to: `vsftpd_3.0.2-1ubuntu2_i386.deb’

100%[=========================================================================================>] 114,714 219K/s in 0.5s

2013-05-20 09:36:21 (219 KB/s) – `vsftpd_3.0.2-1ubuntu2_i386.deb’ saved [114714/114714]

root@ubuntu:~#
root@ubuntu:~#
root@ubuntu:~# dpkg -i vsftpd_3.0.2-1ubuntu2_i386.deb

Install dependency of vsftpd

root@ubuntu:~# apt-get install libcap2

Step3 : Take the backup of Original file

#cp -p vsftpd.conf.dpkg-new vsftpd.conf
# cp -p /etc/vsftpd.conf /etc/vsftpd.conf.orig

Step 4 : Now restart the vsftpd service.

# service vsftpd restart

Now you will be able to login into ftp server with user called anonymous .

How to login into ftp server through command line using anonymous user

=> Open a terminal or command line

=> Write the below command.

linux@tuxworld:/tmp$ ftp 10.10.0.25
Connected to 10.10.0.25.
220 (vsFTPd 3.0.2)
Name (10.10.0.25:linux): anonymous
331 Please specify the password.
Password: (Press only enter,password is nothing)
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory send OK.
ftp>

How to login through webbrowser using anonymous user

Or , Open the webbrowser like firefox,chrome etc.
In URL type ftp://ipaddress_of_ftp-server OR ftp://FTP-server-domain-name

ftp

NOTE: IN Ubuntu , by default location of ftp directory for anonymous user is /srv/ftp . So you can put files and directory in /srv/ftp directory and through ftp anonymous user can download the stuffs

eg. In below method I created a file in /srv/ftp . You can also place the files and directory in /srv/ftp

root@ubuntu:~# cd /srv/ftp/
root@ubuntu:/srv/ftp# ls
root@ubuntu:/srv/ftp# echo “This is a test file” > testfile
root@ubuntu:/srv/ftp# ls -l
total 4
-rw-r–r– 1 root root 20 May 20 09:56 testfile
root@ubuntu:/srv/ftp#

Now we will access the file via command line and web browser both

In command line for downloading the file you have use get or mget command.
See the below given example

linux@tuxworld:/tmp$ ftp 10.10.0.25
Connected to 10.10.0.25.
220 (vsFTPd 3.0.2)
Name (10.10.0.25:linux): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
-rw-r–r– 1 0 0 20 May 20 09:56 testfile
226 Directory send OK.
ftp> get testfile
local: testfile remote: testfile
200 PORT command successful. Consider using PASV.
150 Opening BINARY mode data connection for testfile (20 bytes).
226 Transfer complete.
20 bytes received in 0.00 secs (29.9 kB/s)
ftp>
ftp> bye
221 Goodbye.
linux@tuxworld:/tmp$ ls -l testfile
-rw-rw-r– 1 linux linux 20 May 21 01:33 testfile
linux@tuxworld:/tmp$ cat testfile
This is a test file
linux@tuxworld:/tmp$

with the help of wget command you can also download the file from ftp server.see the below eg.

linux@tuxworld:/tmp$ wget ftp://10.10.0.25/testfile
–2013-05-21 01:38:35– ftp://10.10.0.25/testfile
=> `testfile’
Connecting to 10.10.0.25:21… connected.
Logging in as anonymous … Logged in!
==> SYST … done. ==> PWD … done.
==> TYPE I … done. ==> CWD not needed.
==> SIZE testfile … 20
==> PASV … done. ==> RETR testfile … done.
Length: 20 (unauthoritative)

100%[========================================================================================>] 20 –.-K/s in 0s

2013-05-21 01:38:35 (2.97 MB/s) – `testfile’ saved [20]

linux@tuxworld:/tmp$ ls testfile
testfile
linux@tuxworld:/tmp$

In browser, in url type ftp://ipaddress-of-ftpserver. It will show the files. By clicking on file you can download it.

ftp2

How to allow anonymous user to upload files or directory

Note: Because of security reason it is recommended to do not allow anonymous user to upload the file. Hence for learning purpose I am writing this section. Reason system admin is like a warrior who is protecting the castle, you can not well protect the castle if you do not know what are its security loopholes.

Rest is if it is require in your network you can allow anonymous user to upload files.

Step 1: eg. Create new directory with any name here we call it as anon in /srv/ftp and change its ownership and group to ftp

root@ubuntu:/srv/ftp# mkdir -p /srv/ftp/anon
root@ubuntu:/srv/ftp# chown ftp:ftp /srv/ftp/anon
root@ubuntu:/srv/ftp# ls -ld /srv/ftp/anon
drwxr-xr-x 2 ftp ftp 4096 May 20 10:30 /srv/ftp/anon
root@ubuntu:/srv/ftp#

Step 2: Enable two parameters in vsftpd.conf file

root@ubuntu:~# vi /etc/vsftpd.conf

write_enable=YES
anon_upload_enable=YES

Step 3: Now restart the vsftpd service

service vsftpd restart

Now we will upload the file using anonymous user in /srv/ftp/anon directory

For uploading the file use put or mput command.
note: put for single file and mput is for multiple files

linux@tuxworld:/tmp$ ftp 10.10.0.25
Connected to 10.10.0.25.
220 (vsFTPd 3.0.2)
Name (10.10.0.25:linux): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x 2 107 114 4096 May 20 10:30 anon
-rw-r–r– 1 0 0 20 May 20 09:56 testfile
226 Directory send OK.
ftp> cd anon
250 Directory successfully changed.
ftp> put upload.txt
local: upload.txt remote: upload.txt
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
21 bytes sent in 0.00 secs (173.8 kB/s)
ftp>

Now check the file in FTP server it will be there.

root@ubuntu:~# ls -l /srv/ftp/anon/
total 4
-rw——- 1 ftp ftp 21 May 20 10:31 upload.txt
root@ubuntu:~#

How to allow anonymous user to create directory in FTP Server

This is also not recommended one but for learning we are writing on this topic as well

Step1: Enable the parameter called anon_mkdir_write_enable=YES in /etc/vsftpd.conf file

vi /etc/vsftpd.conf

anon_mkdir_write_enable=YES

Step2: Restart the vsftpd service

service vsftpd restart

Now we will try creating directory from remote client
Note: We can here only able to create directory inside anon directory only.

linux@tuxworld:/tmp$ ftp 10.10.0.25
Connected to 10.10.0.25.
220 (vsFTPd 3.0.2)
Name (10.10.0.25:linux): anonymous
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x 2 107 114 4096 May 20 10:31 anon
-rw-r–r– 1 0 0 20 May 20 09:56 testfile
226 Directory send OK.
ftp> mkdir wiki
550 Create directory operation failed.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwxr-xr-x 2 107 114 4096 May 20 10:31 anon
-rw-r–r– 1 0 0 20 May 20 09:56 testfile
226 Directory send OK.
ftp> cd anon
250 Directory successfully changed.
ftp> mkdir linux
257 “/anon/linux” created
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
drwx—— 2 107 114 4096 May 20 10:47 linux
-rw——- 1 107 114 21 May 20 10:31 upload.txt
226 Directory send OK.
ftp>

Desktop FTP clients

You can also access the FTP server through desktop client. These clients are free and opensource
(1) filezilla (Windows,Linux and MAC) https://filezilla-project.org/download.php
(2) fireftp (firefox plugin)    https://addons.mozilla.org/en-US/firefox/addon/fireftp/
(3) cyberduck (MAC and Windows)  http://cyberduck.ch/

For login with system user and disabling anonymous user,read the given below post

How to install and configure Secure FTP server in Ubuntu 12.04 LTS

2 thoughts on “How to install and configure FTP server in Ubuntu 12.04 LTS”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.