This article provides detailed steps on setting up SSH keys to enable passwordless SSH between Linux hosts.
For example lets assume you want to enable passwordless SSH between two Linux hosts source-vm and target-vm, where source-vm is the host from which you want to connect to target-vm host via SSH without password prompt, below are steps to follow.
1. On source-vm cd .ssh directory inside user home directory. Below command can be used.
2. Create SSH rsa keypair using below command.
Below is example output of above command.
Once above command is executed, we will see below files inside <user home>/.ssh directory on source-VM.
3. Now copy the public key id_rsa.pub from source-vm <userhome>/.ssh directory to target-vm <user_home> directory. This can be done using scp command.
Other option is to copy public key from source-vm to target-vm as authorized_keys in ~/.ssh/ directory. For this below command can be used.
4. Now test passwordless ssh from source-vm to target-vm using ssh command as follows on source-vm.
You should be logged into target-vm from source-vm without being prompted for password.
All Linux Operating Systems. The steps in this article should also work on other UNIX bases Operating systems.
For example lets assume you want to enable passwordless SSH between two Linux hosts source-vm and target-vm, where source-vm is the host from which you want to connect to target-vm host via SSH without password prompt, below are steps to follow.
1. On source-vm cd .ssh directory inside user home directory. Below command can be used.
cd $HOME/.ssh
2. Create SSH rsa keypair using below command.
ssh-keygen -t rsa
Below is example output of above command.
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:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
0b:12:45:53:31:78:64:7d:68:b9:1c:54:36:2d:51:3e root@source-vm
The key's randomart image is:
+--[ RSA 2048]----+
| .++*+.+=+. |
| ..o..*.oo. |
| . . o + .E |
| . o . |
| . . S |
| . . . |
| . |
| |
| |
+-----------------+
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
0b:12:45:53:31:78:64:7d:68:b9:1c:54:36:2d:51:3e root@source-vm
The key's randomart image is:
+--[ RSA 2048]----+
| .++*+.+=+. |
| ..o..*.oo. |
| . . o + .E |
| . o . |
| . . S |
| . . . |
| . |
| |
| |
+-----------------+
Once above command is executed, we will see below files inside <user home>/.ssh directory on source-VM.
authorized_keys
id_rsa
id_rsa.pub
known_hosts
id_rsa
id_rsa.pub
known_hosts
3. Now copy the public key id_rsa.pub from source-vm <userhome>/.ssh directory to target-vm <user_home> directory. This can be done using scp command.
ssh-copy-id -i $HOME/.ssh/id_rsa.pub <user>@target-vm
Other option is to copy public key from source-vm to target-vm as authorized_keys in ~/.ssh/ directory. For this below command can be used.
scp $HOME/.ssh/id_rsa.pub <user>@target-vm:~/.ssh/authorized_keys
4. Now test passwordless ssh from source-vm to target-vm using ssh command as follows on source-vm.
ssh <user>@target-vm
You should be logged into target-vm from source-vm without being prompted for password.
Products to which Article Applies
All Linux Operating Systems. The steps in this article should also work on other UNIX bases Operating systems.
No comments:
Post a Comment