In this tutorial we will learn how to install and configure vsftpd server in Ubuntu 12.04 LTS
We will configure the FTP server for anonymous user only.
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/
Steps To Install FTP Server
FTP Server IP Address = 10.10.0.25
Step 1: login into system and become superuser root
sudo 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:~# apt-get install libcap2
root@ubuntu:~# dpkg -i vsftpd_3.0.2-1ubuntu2_i386.deb
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 .
Login into ftp server through cli as anonymous user
Open a terminal or command line, write the given 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>
Login through web browser as an anonymous user
Open the web browser like firefox, chrome etc.
In URL type ftp://ipaddress_of_ftp-server or ftp://FTP-server-domain-name
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
Example, In given below method we 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#
Access files in FTP Server through command line and web browser
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, find the given below example.
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.
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:~#
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 List
- You can also access the FTP server through desktop client. These clients are free and opensource filezilla (Windows,Linux and MAC) https://filezilla-project.org/download.php
- cyberduck (MAC and Windows)https://cyberduck.io/
Reference
For login with system user and disabling anonymous user, read our this post.
Which package should I download for use on x64 Intel architecture?
always select latest package. For 64 bit Ubuntu,it will work http://security.ubuntu.com/ubuntu/pool/main/v/vsftpd/vsftpd_3.0.2-1ubuntu2_amd64.deb