Thursday, June 2, 2016

[Quick Install: SSH Passwordless]: Password less authentication to run scripts an remote server – Linux

Password less authentication to run scripts an remote server – Linux

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.
For more information, visit this page.
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 privkey 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.

No comments: