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
Make yourself a pubkey/privkey pair:
$ ssh-keygen -t dsa
Rename the pubkey to authorized_keys:
$ cd ~/.ssh $ mv id_dsa.pub authorized_keys
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>
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
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…
Key based authentication is the mostly used handy method to run shell scripts on multiple servers and more secure then credential method.
Thanks for your wonderful Support and Encouragement