Password less authentication to run scripts an remote server – Linux

Password less authentication to run scripts an remote server – Linux.  When you want to execute commands in multiple servers yet the same time you can simply write shell scripts and run, but when your running it will ask for remote server user name and password. Typing each and every server credentials there is no need of writing shell scripts in that case. To avoid such a kind of situations simply make password less authentication (Key based authentication).

Public Key Authentication password less authentication

Background Information: Public key cryptography, also known as asymmetric cryptography uses two keys, each of which can be used to encrypt a message. If one key is used to encrypt a message, then the other must be used to decrypt it. This makes it possible to receive secure messages by simply publishing one key (the public key) and keeping the other secret (the private key).

Anyone may encrypt a message using the public key, but only the owner of the private key is able to read it. In this way, Alice may send private messages to the owner of a key-pair (the bank) by encrypting it using their public key. Only the bank can decrypt it.

Password Less Authentication (Key Based Authentication)
SSH pubkey authorization

Step 1
Make yourself a pubkey/privkey pair:

$ ssh-keygen -t dsa

Step 2
Rename the pubkey to authorized_keys:

$ cd ~/.ssh 
$ mv id_dsa.pub authorized_keys

Step 3
Scp the authorized_keys file into ~/.ssh/ on all machines you want to be able to connect to. you can also use below mentioned command to copy the pubkey to remote host.

$ ssh-copy-id <Remote Host IP>

Step 4
Run the ssh-agent and load your private key into it. Use the following script, which is called “sshrun”, to do that.

#!/bin/sh eval `ssh-agent` ssh-add ~/.ssh/id_dsa bash ssh-agent -k exec clear

Step 5
Try ssh into one of the boxes in question. If it doesn’t let you in without a password, it’s probably a file or directory permissions problem.

You feedback is valuable to us…

Conclusion

Key based authentication is the mostly used handy method to run shell scripts on multiple servers and more secure then credential method.

Click Here for Video Tutorials

Related Articles

ClusterSSH Helps you to run same command in multi hosts

subversion server setup RHEL 7

Network Security and Protocols

Thanks for your wonderful Support and Encouragement

Ankam Ravi Kumar

Working as Linux / Storage Administrator L3. Interested in sharing the knowledge.

Leave a Reply

Your email address will not be published.