Wednesday, April 10, 2013

setting up passwordless ssh

Why do you need password-less ssh ?
You want to use Linux and OpenSSH to automize your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script

Is it Secure?
Yes. As long as you do not share your keys files

What are keys?
Keys are encrypted authentication files which automatically get checked when you login from one machine to another.
There are two major key types

Which one to choose? 
Choice is yours. 
DSA keys provide smaller keys and faster operations so I choose dsa most of the times. Please note this may not work with older OPENSSH versions


What do I need ?
at least one linux machine
OPENSSH installed
one user with ssh permissions

How do I Do it?

  1. if want then create a separate user . I will create user named test
    • useradd test
    • login to users shell : sudo su - test
  2. create .ssh directory default location. You can store the keys anywhere you need but then you will need lot of other configurations. So lets go with default
    • mkdir -p ~/.ssh
  3. create the key 
    • command which creates keys is ssh-keygen. First decide which type and then run
    • ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
  4. Above command will create two files in directory ~/.ssh. One is your private key file and other is public key file. change permission of both files to read only by user
    1. chmod 400 ~/.ssh/id_dsa*
  5. copy the contents of the .pub file into another machine or same machine's .ssh/authorized_keys
  6. Change permission for RW user only. chmod +600 .ssh/authorized_keys
  7. now you can ssh from first machine to second machine without inputing your password

No comments:

Post a Comment