Log in with an SSH private key on Linux

Using a text editor, create a file in which to store your private key. This example uses the file private_key.txt.
To edit the file in nano, type the following command


# nano deployment_key.txt

Paste the private key into the file. Be sure to include the BEGIN and END lines.

-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAx9ODcgSZFhPnZmW/VGWy/bXLKFBhOoTP9k4dhcJq17ZuG9KB
...
-----END RSA PRIVATE KEY-----

Run the following command to change the file permissions to 600 to secure the key. You can also set them to 400. This step is required:


# chmod 600 deployment_key.txt

Use the key to log in to the SSH client as shown in the following example, which loads the key in file private_key.txt, and logs in as user demo,to IP 192.237.248.66:


# ssh -i deployment_key.txt demo@192.237.248.66

When the prompt to confirm the connection request is displayed, type yes and then press Enter.

If your SSH key requires a password, enter it when prompted to complete the connection.

Leave a Comment