4

If you run the following command on a Linux/Unix machine, among other things, you get a prompt for a password:

$ ssh-keygen -t dsa
Enter passphrase (empty for no passphrase): 

What does adding a password to your SSH key actually do? Is it more secure to use a password when prompted?

7

Many users do not encrypt their hard drive. If you leave an ssh private key on an unencrypted hard drive, anyone with physical access to the hard drive can come along and steal your private key.1 Then they can use this key (along with computers you frequently connect to with that key taken from ~/.ssh/config, ~/.ssh/known_hosts, ~/.history) and use it to connect to a bunch of other machines you have access to, which is generally a very bad thing.

1 All an attacker has to do is either take out the hard drive from the machine and either mount it externally in another machine or boot into another operating system (e.g., from a live cd/usb) or just boot into single user mode. Then they can cp the private ssh key even if the read permissions were limited in the original OS and the login for the user with read permissions had a very strong password. Granted, if you have unrestricted physical access to the machine with the private key stored on it, it is also possible to say attempt to install a hardware keylogger and capture the passphrase to the private key/encrypted drive, but its a more effort (and harder in some scenarios; e.g., laptops).

6

Adding a password to your SSH key means that the private key will be stored encrypted on your local machine. That private key is a rather sensitive secret since knowing that key grants access to all servers on which you registered the corresponding public key (in your .ssh/authorized_keys file).

Secrets in local files can be plundered by attackers in various occasions:

  • Your laptop is stolen.
  • Your harddisk breaks down (it happens) and you discard it, and the attacker retrieves it from your dumpster, repairs it (e.g. the broken part was the electronic board, and the attacker simply replaces it), and reads your files.
  • You make a backup of your files on some external device (USB drive, tape...) and the attacker steals it.
  • Some malware on your machine takes a peek at your files and uploads your private keys to a server in Uzbekistan.
  • Through some unfortunate configuration mishap, you make your files available to the world at large (e.g. with disk sharing, or with a local Web server which was not correctly setup).
  • A vulnerability in your Web browser temporarily allows evil-minded Javascript to read and upload some arbitrary files, e.g. your SSH private keys.

This list is not exhaustive. In all these occasions, password-based encryption of your SSH private key will make the life harder for the attacker. Note that your files are likely to contain other sensitive information as well, so SSH private key encryption is not sufficient to reach the beatitude of absolute security; however, it helps.

Of course, there is nothing completely free. If you use a password to protect the on-disk storage of your private key, then you will have to type that password on a regular basis. As usual, security and convenience are two sides of a trade-off.

3

It prevents root or other users who might have access to your key file (by design, by accident, or by privlege escalation) from using your key to log into other systems.

  • Just to be clear, this protects the private key (usually stored as id_dsa), and adds no visible effect or requirement on the public key that I send to others, correct? – IQAndreas May 21 '14 at 20:24
  • 1
    Correct, the passphrase to the private key file lets a process access the private key. Think of it as a tiny encrypted volume. The id_rsa file, with a passphrase, has the encrypted private key value stored inside it; the passphrase is how that stored key is decrypted and exposed. – 0xSheepdog May 21 '14 at 20:29
  • 1
    @0xSheepdog I love that explanation, perfectly clear! If Rod has no plans to edit that information into his answer, I would love it if you added that explanation as a new one. – IQAndreas May 21 '14 at 20:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.