Configure the FTP server in Linux

FTP Server (File Transfer Protocol)

It is the standard network protocol used to transfer computer files between one host(Server) to another host(Client) over a TCP-based network, such as the  Internet.

The FTP server uses two ports for the transferring purpose, one for commands and the other for sending and receiving Data.

Once the user enters the name of the server and the login credentials in the authorization fields of the FTP client, the FTP connection is established and the FTP control port of the FTP server (the default port for sending commands is 21) is opened. Then a second connection to the server is made by the client, followed by a response of the FTP server from the port for sending data (the default data sending port is 20), when the real file transfer actually begins.

Note that only FTP servers use port 21, not FTP clients.

Outline of FTP server

  • Package used by server      :       vsftpd
  • Port number                        :        20 (FTP-Date sending port), 21 (FTP-Control port)
  • Document Root                   :        /var/ftp
  • Configuration files              :        /etc/vsftpd/ftpusers, /etc/vsftpd/user_list, /etc/vsftpd/vsftpd.conf

We use 2 machine, one  as the ftp server and other as ftp client machine. Let look at below details for more understanding.

  • ftp server Hostname                            :       server1
  • ftp server Ip address                            :      192.168.1.10
  • ftp client Hostname                             :       client1

 

To configure the ftp server the steps are:

1.) Install the package.

Install the Package using yum command. If you are not configured the YUM server, refer the link(PART2: YUM (Yellowdog Updater Modified))

[root@server1 ~]# yum install -y vsftpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:3.0.2-10.el7 will be installed

.....
Transaction Summary
==========================
Install  1 Package

Total download size: 167 k
Installed size: 347 k
Downloading packages:

2.) Start the service and make the service enable even after reboot of the server.

#systemctl start <service name> This command used for start the service of vsftpd and # systemctl enable <service name> This command used for enable the service after reboot of the server

[root@server1 ~]# systemctl start vsftpd.service ; systemctl enable vsftpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.
[root@server1 ~]# systemctl status vsftpd.service
● vsftpd.service - Vsftpd ftp daemon
   Loaded: loaded (/usr/lib/systemd/system/vsftpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Sun 2016-09-18 00:17:22 EDT; 16s ago
 Main PID: 3039 (vsftpd)
   CGroup: /system.slice/vsftpd.service
           └─3039 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

Sep 18 00:17:22 server1 systemd[1]: Starting Vsftpd ftp daemon...
Sep 18 00:17:22 server1 systemd[1]: Started Vsftpd ftp daemon.
[root@server1 ~]#

3.) Allow ftp service on firewall of the server.

[root@server1 ~]# firewall-cmd --add-service=ftp --permanent
success
[root@server1 ~]# firewall-cmd --reload
success
[root@server1 ~]#

4.) Create some file or directory in /var/ftp/pub directory.

Create some files in “/var/ftp/pub” directory

[root@server1 ~]# cd /var/ftp/pub/
[root@server1 pub]# ls
[root@server1 pub]# mkdir Shared
[root@server1 pub]# touch file{1..4}
[root@server1 pub]# ls
file1  file2  file3  file4  Shared
[root@server1 pub]#

5.) Connect from client machine and access the files using graphically.

Open the web browser like firefox type the ftp server’s ip address as following.

ftp_browser

Note: When we connect ftp server using graphically (like, web browser) By default anonymous FTP is enabled.

6.) Connect from client machine and access the files using CLI mode.

To connect to ftp server from client machine use the following command. Use “ftp or anonymous” as login name and press enter without giving any password.

[root@client1 ~]# ftp 192.168.1.10
-bash: ftp: command not found
[root@server1 ~]# yum install ftp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

. . . . . .
Transaction Summary
==============================
Install  1 Package

Total download size: 61 k
Installed size: 96 k
Is this ok [y/d/N]: y
[root@client1 ~]# ftp 192.168.1.10
Connected to 192.168.1.10 (192.168.1.10).
220 (vsFTPd 3.0.2)
Name (192.168.1.10:gaurav): ftp
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 

Note: Before connect to the ftp server, Check whether ftp package is installed or not, if not then install it.

#cd pub (Go to pub directory & check the files available)

ftp> cd pub
250 Directory successfully changed.
ftp> ls
227 Entering Passive Mode (192,168,1,10,159,12).
150 Here comes the directory listing.
drwxr-xr-x    2 0        0               6 Sep 18 04:40 Shared
-rw-r--r--    1 0        0               0 Sep 18 04:40 file1
-rw-r--r--    1 0        0               0 Sep 18 04:40 file2
-rw-r--r--    1 0        0               0 Sep 18 04:40 file3
-rw-r--r--    1 0        0               0 Sep 18 04:40 file4
226 Directory send OK.
ftp> prompt
Interactive mode off.
ftp> mget file1 file2 file3 
local: file1 remote: file1
227 Entering Passive Mode (192,168,1,10,167,0).
150 Opening BINARY mode data connection for file1 (0 bytes).
226 Transfer complete.
local: file2 remote: file2
227 Entering Passive Mode (192,168,1,10,83,77).
150 Opening BINARY mode data connection for file2 (0 bytes).
226 Transfer complete.
local: file3 remote: file3
227 Entering Passive Mode (192,168,1,10,216,168).
150 Opening BINARY mode data connection for file3 (0 bytes).
226 Transfer complete.
ftp> !ls
anaconda-ks.cfg    file1  file2  file3
ftp>  quit
221 Goodbye.
[root@client1 ~]#

Note: #mget <file names> (Where, mget command used for download multiple files. )  #Prompt command used to turn off interactive mode, So that it will not ask permission for every file you are downloading. And # !ls command used check the files are there or not.

7.)  Upload the files in the ftp server from client machine.

Before that uncomment (remove the #) the 29 line in /etc/vsftpd/vsftpd.conf file, as shown below.

# vi /etc/vsftpd/vsftpd.conf

# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
# When SELinux is enforcing check for SE bool allow_ftpd_anon_write, allow_ftpd_full_access
anon_upload_enable=YES
#

Restart the ftp service.

[root@server1 ~]# systemctl restart vsftpd
[root@server1 ~]#

Note: If the selinux enabled in the ftp server. Do some changes on booleans for ftp using following commands.

[root@server1 ~]# getsebool -a | grep ftp
ftp_home_dir --> off
ftpd_anon_write --> off
ftpd_connect_all_unreserved --> off
ftpd_connect_db --> off
ftpd_full_access --> off

As shown above, “ftpd_anon_write –> off and ftpd_full_access –> off “, Make the boolean value as “on”.

[root@server1 ~]# setsebool -P ftpd_anon_write on;setsebool -P ftpd_full_access on
[root@server1 ~]# getsebool -a | grep ftp 
ftp_home_dir --> off 
ftpd_anon_write --> on 
ftpd_connect_all_unreserved --> off 
ftpd_connect_db --> off
ftpd_full_access --> on

And, Change the user and group owner of Shared directory.

[root@server1 ~]# cd /var/ftp/pub/
[root@server1 pub]# ll
total 0
-rw-r--r--. 1 root root  0 Sep 18 00:40 file1
-rw-r--r--. 1 root root  0 Sep 18 00:40 file2
-rw-r--r--. 1 root root  0 Sep 18 00:40 file3
-rw-r--r--. 1 root root  0 Sep 18 00:40 file4
drwxr-xr-x. 2 root root  6 Sep 18 00:40 Shared
[root@server1 pub]# chown ftp:ftp -R Shared/
[root@server1 pub]#

Continue with next page …

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz