No password SSH – Login to a SSH server with private/public keys

Orange Pi Development Boards

If you often need to establish SSH connections to a server, entering the password each time may be an hassle or even a non-starter. For example, in our case we use ssh connections in our nightly build scripts, so obviously entering a password would not be an option here…

So it can be useful to configure the server and you client to accept secure ssh connection without the need to enter a password.  What must be done, then , is to generate a public/private key pair, and copy the public part into the appropriate place on the server side.

For doing this, on the user’s home directory, on the client machine, type:

local> ssh-keygen -t dsa -f .ssh/id_dsa

-t tells the type of encryption
-f tells where to store the public/private key pairs. In this case, the .ssh directory on home is being used

A password will be asked;  leave this part blank, just press <enter>
Now, go the .ssh directory, and you will find two new files: id_dsa and id_dsa.pub. The last one is the public part. Now, copy the public key to the server machine:

local> cd .ssh
local> scp id_dsa.pub [email protected]:~/.ssh/id_dsa.pub

Of course, this time you will need to enter the password.
Now, login into the server machine and go to the .ssh directory on the server side
local> ssh [email protected]
remote> cd .ssh

Then add the client’s public key to the known public keys on the server:

remote> cat id_dsa.pub >> authorized_keys2
remote> chmod 640 authorized_keys2
remote> rm id_dsa.pub
remote> exit

and that’s all. Next time you log into the remote server, no password will be asked.
If that does not work, you can try to use authorized_keys instead of authorized_keys2, since it may depends on the Linux version used.

Note that this system will work while none of the machines change its IP address and for the specific user, so it is still safe.

Reference: http://www.astro.caltech.edu/~mbonati/WIRC/manual/DATARED/setting_up_no-password_ssh.html (Link is down now)

Support CNX Software - Donate via PayPal or become a Patron on Patreon

5
Leave a Reply

avatar
5 Comment threads
0 Thread replies
1 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Chris SteinbachHow To Use Putty with an SSH Private Key Generated by OpenSSH | CNXSoft – Embedded Software DevelopmentUse GNU Parallel to Speed Up Script Execution on Multiple Cores and/or Machines | CNXSoft – Embedded Software DevelopmentTweets that mention CNXSoft – Embedded Software Development » No password SSH – Login to a SSH server with private/public keys -- Topsy.comCNXSoft – Embedded Software Development » No password SSH – Login … | Linux Affinity Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
trackback

[…] here: CNXSoft – Embedded Software Development » No password SSH – Login … Posted in: Software ADD […]

trackback

[…] This post was mentioned on Twitter: No password SSH – Login to a SSH server with private/public keys http://bit.ly/9AM0nX […]

trackback

[…] to install GNU parallel on all computers and setup your machines so that they can be accessed by ssh without password. (using public/private keys instead).The task is the same, but the command line becomes a little […]

trackback

[…] to login via SSH with a key, and I can’t add an extra key by myself, as described in “No Password SSH” post. The private key (RSA) has been generated with ssh-keygen in Linux, and I can login […]

Chris Steinbach
Guest
Chris Steinbach

The last steps can be replaced with an invocation of the ssh-copy-id command (see https://www.ssh.com/ssh/copy-id).