Convert the public key into specify key format (PKCS8) ssh-keygen -f ~/.ssh/id_rsa.pub -e -m PKCS8 > ~/.ssh/id_rsa.pem Using the public PKCS8 file to encrypt a string echo "sometext" | openssl rsautl -encrypt -pubin -inkey ~/.ssh/id_rsa.pem > ~/encrypted-file.txt OR file openssl rsautl -encrypt -inkey ~/.ssh/id_rsa.pem -pubin -in ~/secure-message-file.txt -out ~/encrypted-file.txt To decrypt, you'll need the private key openssl rsautl -decrypt -inkey ~/.ssh/id_rsa -in ~/encrypted-file.txt -out ~/decrypted-file.txt