Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Some of my Linux & FreeBSD systems have dozens of users. Staff will use these "ssh gateway" nodes to SSH into other internal servers.

We're concerned that some of these people use an unencrypted private SSH key (A key without a passphrase. This is bad, because if a cracker ever gained access to their account on this machine, they could steal the private key and now have access to any machine which uses this same key. For security reasons, we require all users to encrypt their private SSH keys with a passphrase.

How can I tell if a private key is not-encrypted (e.g. Does not contain a passphrase)? Is there a different method to do this on an ASCII-armored key vs. a non-ASCII-armored key?


To clarify, assume I have superuser access on the machine and I can read everybody's private keys.

share|improve this question
grumble ssh-agent grumble There shouldn't be any private keys on the gateway. –  derobert Aug 30 '12 at 15:44

2 Answers 2

up vote 26 down vote accepted

Well, OpenSSH private keys with empty passphrases are actually not encrypted.

Encrypted private keys are declared as such in the private key file. For instance:

Proc-Type: 4,ENCRYPTED


So something like

# grep -L ENCRYPTED /home/*/.ssh/id_[rd]sa

should do the trick.

share|improve this answer
@jmanning2k : I just created an RSA private key with no passphrase, and it does not contain the string 'Encryption: none'. –  Stefan Lasiewski Aug 18 '10 at 17:22
@jmanning2k: the -L flag lists only file names that do not match the pattern. So this answer is correct on its own. –  bahamat Aug 30 '12 at 18:38
I stand corrected, comment removed for clarity. For the record, I have a few Putty private key files copied over, which do read 'Encryption: none'. –  jmanning2k Sep 4 '12 at 20:29

If you have access to the private key, I suppose, you can use it without passphrase to authenticate against the public key. If this works you know it has no passphrase. If it had, it would give you an error message.

If you don't have access to the private key, I doubt you can detect this. The passphrase's purpose is to "unlock" the private key, it has no function in regard to the public key.

In fact, if it would, it would make the system less secure. One could use the public key, that is available to try to mount brute force or other attacks trying to crack the passphrase.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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