Goal: to login from local machine to Remote machine / Server via ssh without typing password
This simple tutorial explains how to SSH to a remote machine without typing your password. You can use this technique if you find yourself logging in to the same machine frequently and find typing your password tedious. It is also useful in scenarios when you have a script which needs to pull some files from a remote machine or perform a task on a remote machine via SSH, and you want to run this script automatically without having a human to type a password. May be deployed on Cloud , setting up a Hadoop Cluster
These instructions work on Linux and Mac. You can achieve the same result on Windows using Putty, but I haven’t documented the putty specific instructions here.
Step 1 of 2 : On local machine: Generate Authentication Keys
- ssh-keygen -t rsa
Accept the default choice. Hit enter.
What just happened?
On your local server you just created 2 files in your ~/.ssh directory.
- [hadoop@uidlt02 ~]$ ls -l ~/.ssh/
- total 16
- -rw-------. 1 hadoop hadoop 1675 May 23 15:30 id_rsa
- -rw-r--r--. 1 hadoop hadoop 406 May 23 15:30 id_rsa.pub
- -rw-r--r--. 1 hadoop hadoop 5488 May 22 04:58 known_hosts
- [hadoop@uidlt02 ~]$
id_rsa contains your private key. id_rsa.pub contains your public key.
Step 2 of 2 : On remote machine: authorize password less login
Login to remote machine
- ssh hostname -l username
Enter yes and press enter.
Enter your password, and hit enter.
Create a .ssh directory on the remote machine and create a
Create a .ssh directory on the remote machine and create a
authorized_keys file in that directory. You need to copy the entire contents of your local machine’s ‘id_rsa.pub’ and paste it in the .authorized_keys file on the remote server.- mkdir -p .ssh
- chmod 700 .ssh
- cd .ssh
- touch authorized_keys
- chmod 644 authorized_keys
- vi authorized_keys
- # copy-paste the entire contents of your local machine's ~/.ssh/id_rsa.pub file in authorized_keys
- # logout
- exit
Important: Make sure you have the right permissions for .ssh directory and authorized_keysfile, as shown in chmod command above otherwise SSH will not honor your authorized_keys.
You should now be able to login to the remote server without typing your password.
- # type this command from your local machine
- ssh hostname -l username
SSH should log you in without password! Now, you can also scp or rsync (over ssh) without having to enter your password.
0 comments:
Post a Comment