public key based authentication
Objective: To run a command on a remote linux machine without entering a password.
Remote Linux Machine (10.1.10.6)
Local Machine (10.1.10.20)
Steps for Local Machine:
-
Generate a public key with command
ssh-keygen -t dsa |
Generating public/private dsa key pair. Enter file in which to save the key (/home/anuj/.ssh/id_dsa): Created directory '/home/anuj/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/anuj/.ssh/id_dsa. Your public key has been saved in /home/anuj/.ssh/id_dsa.pub. The key fingerprint is: 6e:c0:f4:ad:d7:97:37:e6:09:9a:56:ee:79:48:5f:92 anuj@node2.example.com |
Copy generated ‘id_dsa.pub‘ on remote server as ‘authorized_keys’ in ‘.ssh’ under the home directory of intended user for remote command execution. Here in example remote user being used is ‘root‘ of remote machine 10.1.10..6
scp .ssh/id_dsa.pub root@10.1.10.6:.ssh/authorized_keys |
The authenticity of host '10.1.10.6 (10.1.10.6)' can't be established. RSA key fingerprint is 5d:17:94:69:22:6b:c0:99:79:c2:ff:7e:2d:86:9b:d7. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '10.1.10.6' (RSA) to the list of known hosts. root@10.1.10.6's password: id_dsa.pub 100% 617 0.6KB/s 00:00 |
Test the configuration by executing some command as follows: (example command used is ‘uptime‘
ssh root@10.1.10.6 uptime |
12:14:43 up 23:18, 0 users, load average: 0.00, 0.03, 0.05 |
anujhere@gmail.com