(Note: Not work on Git Bash Windows: it will hangs and doesn't respond)
Generate RSA private key: M_E.key $ openssl genrsa -des3 -out M_E.key 2048 Generating RSA private key, 2048 bit long modulus ..........+++ ..........................+++ e is 65537 (0x10001) Enter pass phrase for M_E.key: Set pass phrase for private key Verifying - Enter pass phrase for M_E.key: Generate RSA public key: M_E.pub $ openssl rsa -in M_E.key -pubout > M_E.pub Enter pass phrase for M_E.key: Input pass phrase writing RSA key Use public key(M_E.pub) to encrypt $ echo 'Hello World!'|openssl rsautl -encrypt -pubin -inkey M_E.pub > cipher.txt Use Private Key(M_E.key) to decrypt $ cat cipher.txt | openssl rsautl -decrypt -inkey M_E.key Enter pass phrase for M_E.key: input pass phrase Hello World!
Generate RSA private key and public key $ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/Admin/.ssh/id_rsa): ./M_E_KEY Enter passphrase (empty for no passphrase): Set pass phrase Enter same passphrase again: Your identification has been saved in ./M_E_KEY. Your public key has been saved in ./M_E_KEY.pub. The key fingerprint is: ... The key's randomart image is: ... Convert ssh public key to PEM format(that 'openssl rsautl' can read it) $ ssh-keygen -f M_E_KEY.pub -e -m PKCS8 > M_E_KEY.pem $ echo 'Hello World!' > plain.txt Use public key(M_E_KEY.pem) to encrypt $ openssl rsautl -encrypt -pubin -inkey M_E_KEY.pem -ssl -in plain.txt -out cipher.txt Another way $ echo 'Hello World!' | openssl rsautl -encrypt -pubin -inkey M_E_KEY.pem > cipher.txt $ cat cipher.txt |▒pL▒▒▒8▒▒T+▒*▒Bu▒2▒▒]j... Use private key(M_E_KEY) to decrypt $ cat cipher.txt | openssl rsautl -decrypt -inkey M_E_KEY Hello World! Another way $ openssl rsautl -decrypt -inkey M_E_KEY -in cipher.txt Hello World! Save result to decryptedMessage.txt $ openssl rsautl -decrypt -inkey M_E_KEY -in cipher.txt -out decryptedMessage.txt Another way $ openssl rsautl -decrypt -inkey M_E_KEY -in cipher.txt > decryptedMessage.txtSSH LOGIN By RSA KEY
Send public key(id_rsa.pub) to /home/user/.ssh/authorized_keys of the host(authorized_keys file will automatic create if it not exist) $ ssh-copy-id user@host Send specified publick key to the host $ ssh-copy-id -i ./M_E_KEY.pub user@host Logined to user@host $ sudo vim /etc/ssh/sshd_config Modify: PubkeyAuthentication yes # Enable PublicKey authentication AuthorizedKeysFile .ssh/authorized_keys # Public key path PasswordAuthentication no ssh Login $ ssh -i ~/.ssh/id_rsa user@host or $ ssh user@host (default: -i ~/.ssh/id_rsa)