Monday, April 7, 2014

Password less ftp setup in linux

Environment Details:
Source Server Name: linux_src
Destination Server Name: linux_dest
Operating System: Red Hat Enterprise Linux Server 
Version: Release 6.4

When we connect to a server using ftp, we need to provide the username and password of the destination server.
We are going to setup a password less ftp connection authentication to the destination server

Please follow the below steps

Steps(Destination Server):
1. Verify whether vsftpd package is installed or not on the server, if not then install it.
[root@linux_dest bin]# rpm -qa|grep vsftpd
vsftpd-2.2.2-11.el6.x86_64

2. Take a backup of /etc/vsftpd/vsftpd.conf file and edit the value of anonymous_enable to YES
[root@linux_dest ~]# cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.bak
[root@linux_dest ~]# vi /etc/vsftpd/vsftpd.conf

3. Check whether ftp services are running or not, if not then start it
[root@linux_dest bin]# service vsftpd status
vsftpd is stopped
[root@linux_dest bin]# service vsftpd start
Starting vsftpd for vsftpd:                          [  OK  ]
[root@linux_dest bin]# service vsftpd status
vsftpd (pid 10652) is running...

Configuration on the destination server complete

Verify whether we are able to connect to the destination server using ftp or not(since we have not done any configuration on source server yet, it will ask for a username and password

[oracle@linux_src ~]$ ftp linux_dest
Connected to linux_dest (10.11.11.180).
220 (vsFTPd 2.2.2)
Name (linux_dest:testuser): oracle
331 Please specify the password.
Password:
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

We are good, please follow the below steps on source server

Steps(Source Server from where we are planning to connect to the destination server):
1. In our home directory create a file .netrc and change its permission to 400
[oracle@linux_src ~]$ pwd
/home/oracle
[oracle@linux_src ~]$ touch .netrc
[oracle@linux_src ~]$ chmod 400 .netrc

2. Edit the file .netrc and put the value in the following format
machine <dest_server_name> login <username> password <password>
e.g. machine linux_dest login oracle password oracle

[oracle@linux_src ~]$ vi .netrc

3. cat .netrc
machine linux_dest login oracle password oracle

4. Now issue the ftp command from the source to connect to destination server

[oracle@linux_src ~]$ ftp linux_dest
Connected to linux_dest (10.11.11.180).
220 (vsFTPd 2.2.2)
331 Please specify the password.
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.

We are successfully connected to the destination server without supplying the username and password.