I want to use Python to get public key from private key which is passphrase protected. When there is no passphrase we can easily get it by executing ssh-keygen -y -f id_rsa > id_rsa.pub in bash. But I was not able to find a command or a library which could retrieve the public key from passphrase protected private key , without creating an SSH connection.
Asked
Active
Viewed 322 times
0
-
Perhaps [paramiko](http://www.paramiko.org/) is right for you. [This method](http://docs.paramiko.org/en/2.4/api/keys.html#paramiko.pkey.PKey.from_private_key) seems on point. – President James K. Polk Jun 26 '18 at 16:21
1 Answers
0
When you run
ssh-keygen -y -f id_rsa
on a passphrase protected private key, you are asked for the passphrase to the key.
If you can't provide the key via stdin, for example because you are running from a script, the man page lists the -P
option to ssh-keygen
that allows you to specify the passphrase in the command. So your command invocation could look like this
ssh-keygen -y -f id_rsa -P <your-passphrase>

Korrat
- 307
- 1
- 6
-
Can we provide private key as well in the input instead of file like we did for passphrase in the above command? – Bharat MV Jun 26 '18 at 17:55
-