I'm trying to test if ~/.ssh/id_rsa
is actually password protected.
When you run ssh-keygen
you can choose an empty password, and I'm trying to detect this.
Is that possible with a one-liner?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityIf you execute:
ssh-keygen -y -f ~/.ssh/name_of_key
you will get key printed if there is no password like this:
ssh-keygen -y -f ~/.ssh/id_dsa
ssh-dss AAAAB3NzaC1kc3M....
If there is password of the key you will be asked for it
SSH_ASKPASS=/bin/false ssh-keygen -y -f test_rsa < /dev/null
will simply fail instead of asking for the password.
Jun 29, 2017 at 8:48
If you open the private key file in text editor you will be able to see ENCRYPTED
in the second line of the RSA/DSA key file.
For example:
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-128-CBC,373B504621779D53C72BADE597C531A0
I don't have enough reputation to comment, so I add here.
Thanks to @Ulrich-Schwarz , I extended his answer to check all my keys (the one i generated, so I have the puublic/private pair) in my $HOME/.ssh/ :
for l in $(ls $HOME/.ssh/*.pub)
do key=${l%.*}
if SSH_ASKPASS=/bin/false ssh-keygen -y -f $key < /dev/null > /dev/null 2>&1
then
echo -n "NO password: "
else
echo -n "YES password: "
fi
echo ${key}
done