Password-less Encrypted Connections with OpenSSH
While there are many sites (and manual pages) with this information, it is getting put up here as a quick [1] need to reference. [2] Public KeysSetting up a no-password needed secure shell connection involves public keys. A public is the the id needed on both ends to agree upon a session - at least that is the short short version. The basic steps of setting up SSH keys is:
ConventionsWhile the typographic are inline with what the site usually uses, the host conventions need to be clarified.
Generating KeysFirst the type of key needs to be determined, as of this writing there are two types:
More recent versions of OpenSSH default to version two DSA keys. In this example sshv2 and DSA will be used. jdoe@client: ssh-keygen -t dsa When the passphrase comes up, since this is for no-pass connections, hit enter for each prompt (including the passphrase). Now in jdoe's home directory, a .ssh directory exists with the following files: jdoe@client: ls -al /home/jdoe/.ssh -rw------- 1 jdoe jdoe 668 2005-12-22 04:52 id_dsa -rw-r--r-- 1 jdoe jdoe 598 2005-12-22 04:52 id_dsa.pub The public key file to be used is, Sending the pub key to the Server
Ideally, this could be done via some sort of ultra secure method.
In most cases sending the key file over is simply a matter of
secure copying it. The problem with jdoe@client: ssh server mkdir /home/jdoe/.ssh The authenticity of host 'server.server.srv (192.168.0.50)' can't be established. DSA key fingerprint is xxsomereally:long:list Are you sure you want to continue connecting (yes/no)? yes jdoe.server.srv's password: jdoe@client: ssh server chmod 0600 /home/jdoe/.ssh jdoe.server.srv's password: Now that the permissions and structure are in place, it is time to send the public keys: jdoe@client: scp .ssh/id_dsa.pub server:/home/jdoe/.ssh/authorized_keys jdoe.server.srv's password: That is it, from now one when jdoe types: jdoe@client: ssh server As long as the client and server are on the same version (again - nowadays v2) of the protocol - the connection will no longer require a password. This applies to scp as well. What about Version Differences?That is simple enough, newer versions now pass along the information
and automatically adjust. In the worst case scenario, run ssh in verbose
mode ( jdoe@client: ssh-keygen -t rsa Which will create key files named The Quick GuideFollowing is a simple summary with user jdoe and their
jdoe@client: ssh-keygen -t dsa jdoe@client: ssh server mkdir /home/jdoe/.ssh The authenticity of host 'server.server.srv (192.168.0.50)' can't be established. DSA key fingerprint is xxsomereally:long:list Are you sure you want to continue connecting (yes/no)? yes jdoe.server.srv's password: jdoe@client: ssh server chmod 0600 /home/jdoe/.ssh jdoe.server.srv's password: jdoe@client: scp .ssh/id_dsa.pub server:/home/jdoe/.ssh/authorized_keys jdoe.server.srv's password: jdoe@client: ssh server SummaryOpenSSH offers a lot of capabilities not documented here (yet?) - in the least, setting up password less accounts is pretty straightforward and easy enough for just about any *NIX user. Footnotes
This article also appears at systhread. Special thanks to Jay Fink. |
Comments (5)
As a sys admin, I prefer Jay's approach especially when managing a moderate to large number of machines, for mirroring, for backup, automation, etc.
If I followed your statement that "this article's advice, its a _really_ bad idea" then I'd increase my workload. Also, I don't use X Windows to do work on a number of servers.
Just one exception to an all-emcompassing rule.
Sure, as I mentioned keychain is good for this purpose. I suppose the point is more that we should be encouraging peope to use passphrases and _not_ using them should be something that you really deliberate. i.e. using a passphrase should be the rule not the exception.
Regards
Tim
Thanks!
I should also mention that you dont need X-win to use ssh-add. If you are using windows or mac as your destop OS from which you do your administration, there are putty-agent and a mac sshagent proggie that provide similar functionality.
Regards
Tim
Post a comment
A free account is needed to post. Write your comment here first: your text is kept in this browser while you sign up or log in, and is waiting for you when you come back.
Your message:Sign up and post (it is free) or Log in and post
|
|
A far better way is to use a passphrase and then use ssh-agent to cache your key for you. This gives you the convenience of passwordless authentication together with the peace of mind of knowing that if someone steals your private key they will not be able to use it without breaking your passphrase.
The simplest way to achiev secure passwordless authentication using ssh-agent is to type:
ssh-add
As soon as you log in to your X-windows session. Enter your passphrase when prompted and for the remainder of your session you will have the benifit of passwordless authentication. Don'd forget to lock your desktop session with a screensaver when leaving your pc unattended!
There is an alternative way of having passwordless auth using ssh which is useful for instances where you wish to run cron jobs and other similar tasks without having a X-session on the go. See
http://www.gentoo.org/proj/en/keychain/
For more information on using keychain.
Once again, dont follow this article's advice, its a _really_ bad idea.
Tim