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?

Update:

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

share|improve this question
1  
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 20 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:

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,7BD2F97F977F71FC

BT8CqbQa7nUrtrmMfK2okQLtspAsZJu0ql5LFMnLdTvTj5Sgow7rlGmee5wVuqCI
/clilpIuXtVDH4picQlMcR+pV5Qjkx7BztMscx4RCmcvuWhGeANYgPnav97Tn/zp
...
-----END RSA PRIVATE KEY-----

So something like

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

should do the trick.

share|improve this answer
3  
@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
    
... wrong thread commented on –  JasonG Aug 15 '13 at 19:27
    
oops wrong thread. –  JasonG Aug 15 '13 at 19:28

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

 
discard

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.