Over the last decade, we have seen telnet being replaced by the ssh protocol, which ensures secure encrypted traffic including the passwords. However, no matter how secure the technology is, users can always open up a security hole for the sake of convenience. In the case of Openssh, one common misused feature is the RSA/DSA key authentication system. Imagine the following situation: John is a new system administrator in a small company, who is responsible for twenty Linux machines. His tasks require his logging into different systems and copying files from each other. He knows that ssh and scp (secure copy) is a much more secure option than telnet. However, he soon finds typing passwords for every login and scp very tedious. Therefore, he wants a passwordless authentication. With some googling in the Internet, John found his solution: RSA/DSA key authentication. Then John set up his passwordless login in ten minutes with an UNENCRYPTED private key sitting in his harddisk. Unfortunately, his private key was stolen by some spyware. The next day, John finds his boss furious that all servers' data were erased by someone. And our poor John lost his first job.
In this article, I'm going to show you how to properly set up a passwordless DSA key authentication using Keychain. Then I will explain what is happening behind the scene, and evaluate the benefits and risks of such a setup; and finally I will look at some other possible use of the keybased authentication technology.
The following instructions are based on a Gentoo Linux system:
$ ssh-keygen -t dsa
(Accept the default values, and enter a STRONG passphrase.)
- Append localhost:~/.ssh/id_dsa.pub to remotehost:~/.ssh/authorized_keys
$ emerge keychain
$ keychain --clear ~/.ssh/id_dsa
(Enter your passphrase.)
- Append "source ~/.keychain/$HOSTNAME-sh" to your ~/.bashrc ONCE.
- Start a new prompt, and ssh to remotehost.
Note: the $ indicates a prompt input.
Now, you should be able to log into remotehost without a password. So what's the magic behind all this wonderful passwordless login? Let us look at the steps one by one.
In step 1, we created an asymmetric DSA key pair - one public key that you can give to anyone and one private key that you keep strictly to yourself. DSA stands for Digital Signature Algorithm, which reasonably ensures the infeasibility to recover the private key from a known public key, and decrypt messages encrypted with the public key without the private key. As the name implies, the DSA key pair is some kind of signature to prove your identity. This key pair is the core part of the DSA key authentication. The way it works in a deployed key-based authentication system is: the server generates a random number and encrypts it with your public key. Then the encrypted message is sent to the client through the already established ssh secure channel. Next, the client uses your private key to decrypt the number and send it back to the server to prove that you are the holder of the matched private key, thus your identity is verified and the server logs you in. Step 2 is simply installing your public key to the remote host, i.e. the server.
Note that you have to enter a STRONG passphase in the key generation to encrypt your private key. Otherwise, you will find yourself in the same shoes as our poor John. I know an unencrypted private key is the quick, but insecure, way to achieve passwordless login. But hold on, we have a better way. And it's just a three-step process.
In step 3, I installed keychain, the bash-based ssh-agent frontend that helps us accomplish passwordless logins. In step 4, I started keychain with the --clear option, which I will explain later, using my newly created encrypted private key. This step starts a ssh-agent daemon (a background process), which caches your unencrypted private key after you enter the correct passphrase. The cache is valid until a new login happens. In step 5, I set up the user profile so that ssh-agent's PID (process ID) and its authentication sock are exported to the appropriate environment variables whenever a new prompt is started. Now any subsequent ssh or scp operation can grab the cached private key through ssh-agent and establish a secure connection without passwords.
Most users will stop right here and enjoy their new found convenience. However, we cannot stop without understanding its ramification when the security mechanism is altered. Next, I will lay out the benefits and risks pertaining to this keybased passwordless setup.
- "Passwords, 1/2"
- "Passwords, 2/2"