Create a file:
echo ‘This is a sekret’ >/tmp/msg.txt

Export public key:
openssl rsa -in ~/private.pem -out /tmp/ -outform PEM -pubout

Encrypt file with public key (anyone can have this key):
openssl rsautl -encrypt -inkey /tmp/ -pubin -in /tmp/msg.txt -out /tmp/file.enc

Decrypt the file with private key (only you should have the private key):
openssl rsautl -decrypt -inkey ~/private.pem -in /tmp/file.enc -out /tmp/decrypted.txt

Check decoded message:
cat /tmp/decrypted.txt

By Jon

One thought on “Use your ssh key to encrypt / decrypt files”
  1. You can also use this code
    rsautl -encrypt -inkey /tmp/ -pubin -in /tmp/msg.txt -out /tmp/file.enc to encrypt the file and decrypt using this code
    openssl rsautl -decrypt -inkey ~/private.pem -in /tmp/file.enc -out /tmp/decrypted.txt .

    Silvester Norman

    Change Mac Address

Leave a Reply