For many reasons we need to access remote server automatically without providing password. Specially when you need to copy file through script or programming from one server to another server. We know that SSH is a secure protocol to access remote server. Here we will show how we can access remote server without providing password. We have two servers: cgvm01 and cgvm02 ; and we will automatically login from cgvm01 to cgvm02.
Step 1: Create key
[[email protected] ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
When you will be asked to enter passpharase keep it blank.
Step 2: Copy Key to remote host
[[email protected] ~]# ssh-copy-id [email protected]
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed — if you are prompted now it is to install the new keys
[email protected]’s password:
Number of key(s) added: 1
Now try logging into the machine, with: “ssh ‘[email protected]′”
and check to make sure that only the key(s) you wanted were added.
Here cgvm01 is the remote host. You need to provide its password against the provided user.
Step 3: login to remote host
You don’t need to provide password any more.