I've probably forgotten the password for my SSH key. Again.
But I've a hunch what it might be. How do I check if I'm right?
I've probably forgotten the password for my SSH key. Again.
But I've a hunch what it might be. How do I check if I'm right?
If your passphrase is to unlock your SSH key and don't have
ssh-agent
, but do have sshd (the SSH daemon) installed on your machine:Where
~/.ssh/id_rsa.pub
is the public key, and~/.ssh/id_rsa
is the private key.ssh-keygen -y
will prompt you for the passphrase (if there is one).If you input the correct passphrase, it will show you the associated public key.
If you input the wrong passphrase, it will display
load failed
.If the key has no passphrase, it will not prompt you for a passphrase and will immediately show you the associated public key.
e.g.,
Create a new public/private key pair, with or without a passphrase:
Now see if you can access the key pair:
Following is an extended example, showing output.
Create a new public/private key pair, with or without a passphrase:
Attempt to access the key pair by inputting the correct passphrase. Note that the public key will be shown and the exit status (
$?
) will be0
to indicate success:Attempt to access the key pair by inputting an incorrect passphrase. Note that the "load failed" error message will be displayed (message may differ depending on OS) and the exit status (
$?
) will be1
to indicate an error:Attempt to access a key pair that has no passphrase. Note that there is no prompt for the passphrase, the public key will be displayed, and the exit status (
$?
) will be0
to indicate success:You can verify your SSH key passphrase by attempting to load it into your SSH agent. With OpenSSH this is done via
ssh-add
.Once you're done, remember to unload your SSH passphrase from terminal by running
ssh-add -d
Extending @RobBednark's solution to a specific Windows + PuTTY scenario, you can do so:
Generate SSH key pair with PuTTYgen (following Manually generating your SSH key in Windows), saving it to a PPK file;
With the context menu in Windows Explorer, choose Edit with PuTTYgen. It will prompt for a password.
If you type the wrong password, it will just prompt again.
Note, if you like to type, use the following command on a folder that contains the PPK file:
puttygen private-key.ppk -y
.