Thursday, 10 September 2020

How to test SSH key password on Ubuntu?

 How to test password for a private SSH key?


If id_rsa and id_rsa.pub is a keypair, we can execute (after we go to directory whey they reside like e.g.  cd ~/.ssh/):

ssh-keygen -y -f id_rsa

...which will prompt us to enter the password. If correct, this will output the public key.

-y This option will read a private OpenSSH format file and print an OpenSSH public key to stdout.
-f filename  Specifies the filename of the key file.

If you download key pair from another machine, this operation might fail with error:

ssh-keygen -y -f id_rsa
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0664 for 'id_rsa' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "id_rsa": bad permissions

To fix this change permissions on file:

$ chmod 400 id_rsa

If private key is not password protected, user will not be prompted to enter it.

No comments: