Created
February 16, 2017 16:30
-
-
Save phrfpeixoto/8b04a2516ec559eddbfe7520ddde9ad2 to your computer and use it in GitHub Desktop.
Using SSH public key to encrypt a file or string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Recently I had to send a password to someone over Skype. Since that's obviously not a good idea, I asked for | |
# the person's public SSH RSA key, and used it to encrypt the password itself. | |
# Convert the public key into PEM format | |
ssh-keygen -f path/to/id_rsa.pub -e -m pem > ~/id_rsa.pub.pem | |
# Using the public pem file to encrypt a string | |
echo "sometext" | openssl rsautl -encrypt -pubin -inkey ~/id_rsa.pub.pem > ~/encrypted.txt | |
# Or a file | |
cat ~/some_file.txt | openssl rsautl -encrypt -pubin -inkey ~/id_rsa.pub.pem > ~/encrypted.txt | |
# To decrypt, you'll need the private key | |
cat ~/encrypted.txt | openssl rsautl -decrypt -inkey path/to/id_rsa > ~/decrypted.txt |
use this to convert your existing key to pem
ssh-keygen -f ~/.ssh/id_rsa.pub -e -m PKCS8 > id_rsa.pem.pub
and all works
use this to convert your existing key to pem
ssh-keygen -f ~/.ssh/id_rsa.pub -e -m PKCS8 > id_rsa.pem.pub
and all works
This worked for me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Okay, for anyone facing
unable to load public key error
:vi ~/.ssh/id_rsa
) and confirm your key is in OPENSSH key formatthen you can execute OP commands.
If you want to create new key in PEM format, execute below commands: