Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

SCP Command Without Prompt Password

Dear all, when use scp command, we are asked the password on remote server right ? In some cases, i need scp command without password. For example, when executed script backup database, backup automatically transfered to another server.

Okay, here some steps :

Server 1, hostname : sitea IP : 192.168.112.163
Server 2, hostname : siteb IP : 192.168.112.166

1. Try to ssh to target server
[root@sitea ~]# ssh 192.168.112.166 date

it creates directory /root/.ssh/ automatically

2. Create public and private key on server 1
[root@sitea ~]# ssh-keygen -t rsa

it creates private key and public key
[root@sitea ~]# ls -1 /root/.ssh/id_rsa*
/root/.ssh/id_rsa
/root/.ssh/id_rsa.pub

3. Copy public key to server 2
 [root@sitea ~]# scp /root/.ssh/id_rsa.pub root@192.168.112.166:/home

4. Copy the contents of id_rsa.pub to ~/.ssh/authorized_keys
 [root@siteb ~]# cat /home/id_rsa.pub >> ~/.ssh/authorized_keys
 [root@siteb ~]#chmod 700 ~/.ssh/authorized_keys

5. Edit /etc/hosts
192.168.112.163     sitea
192.168.112.166     siteb

Now, we can do command scp without password