How To Setup FTP Server on Linux (RHEL)


"Nothing is true, everything is permitted"
--Anonymous
FTP or File Transfer Protocol is used to transfer files between computers. In this post we will see how to Setup FTP Server in Linux Red-Hat. Once a FTP server is configured and running, we can use a FTP client from a remote computer to connect to the server and transfer files between the server and client.
We will be using the vsftpd(Very Secure FTP Daemon) FTP server which is the default FTP server in most Linux distribution. This is the best free and secure FTP server for Linux machines and its very easy to configure. You can use any FTP client to connect to vsftpd server.

1. Install vsftpd:
[root@jadevm1 ~]# yum install vsftpd
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
Updating certificate-based repositories.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package vsftpd.x86_64 0:2.2.2-11.el6_4.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved
================================================================================
 Package     Arch        Version                 Repository                Size
================================================================================
Installing:
 vsftpd      x86_64      2.2.2-11.el6_4.1        xxxxx-RHEL6-x86-64      151 k

Transaction Summary
================================================================================
Install       1 Package(s)

Total download size: 151 k
Installed size: 331 k
Is this ok [y/N]: y
Downloading Packages:
vsftpd-2.2.2-11.el6_4.1.x86_64.rpm                       | 151 kB     00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
  Installing : vsftpd-2.2.2-11.el6_4.1.x86_64                               1/1
Installed:
  vsftpd.x86_64 0:2.2.2-11.el6_4.1
Complete!

2. Start the ftp service:
[root@jadevm1 ~]# service vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]

3. Check if the service is started:
[root@jadevm1 ~]# service vsftpd status
vsftpd (pid 4321) is running...

[root@jadevm1 ~]# ps -ef | grep ftp
root      2811     1  0 18:13 ?        00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf

4. Execute this in order to automatically start the service at boot time:
[root@jadevm1 ~]# chkconfig vsftpd on

5. Restarting vsftpd service(optional):
[root@jadevm1 ~]# service vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]

6. Now add a user for ftp access:
[root@jadevm1 ~]# adduser -m ftpuser
[root@jadevm1 ~]# passwd ftpuser
Changing password for user ftpuser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

7. Disable SELINUX restrictions:
SELinux prevents ftp daemon from reading users home directories. FTP access will fail with:
......
......
500 OOPS: cannot change directory:/home/ftpuser
500 OOPS: child died
Connection closed by remote host.
There are various way to fix this. Execute setsebool:
[root@jadevm1 ~]# setsebool -P ftp_home_dir=1
Or, use setenforce command to disable SELinux temporarily until reboot:
# setenforce Permissive
Or, disable SELinux permanently:
# vi /etc/sysconfig/selinux
Set SELINUX=disabled
And reboot box.

8. Finally check sending a file to the ftp server:
C:\Users\sa123>ftp jadevm1.idc.xxxxx.xxxxx.com
Connected to jadevm1.idc.xxxxx.xxxxx.com.
220 (vsFTPd 2.2.2)
User (jadevm1.idc.xxxxx.xxxxx.com:(none)): ftpuser
331 Please specify the password.
Password:
230 Login successful.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
226 Directory send OK.
ftp> put build.xml
200 PORT command successful. Consider using PASV.
150 Ok to send data.
226 Transfer complete.
ftp: 7733 bytes sent in 0.15Seconds 51.21Kbytes/sec.
ftp> ls
200 PORT command successful. Consider using PASV.
150 Here comes the directory listing.
build.xml
226 Directory send OK.
ftp: 11 bytes received in 0.00Seconds 11.00Kbytes/sec.
ftp> bye
221 Goodbye.

Great, we have our Linux FTP server ready, now we can also use any FTP clients or tools to connect to our FTP server. Go ahead and download a free FTP client like FileZilla or WinSCP in Windows and transfer files between Linux and Windows.

1 comment: