July 27, 2020

Access remote machine with ssh key

This post is going to show a example how you can access a remote linux machine with a ssh client from your local machine.

This approach is very common when you want to access or use any port forwarding on a remote machine.

Create a ssh-key

Start by creating a ssh-key if you don’t already have one on your local machine:

ssh-keygen

Run the above command and follow the instructions. Default path to your ssh keys is ~/.ssh/id_rsa. Suggestion is to keep the id_rsa name if you don’t already have a ssh key with that name.

Add public key to the remote machine

Once the ssh-key has been generated you can copy the content from the public key cat ~/.ssh/id_rsa.pub on your local machine.

The public key content above should be appended to the remote machine authorized keys file.

echo [put-content-from-local ~/.ssh/id_rsa.pub here] >> ~/.ssh/authorized_keys

The public key is granting your local ssh-key to the remote machine when appended to ~/.ssh/authorized_keys.

Access remote machine

Now you can access the remote machine by running:

ssh user@server

Where user is the user you want to login as on the remote machine, and server is usually a IP or DNS record.

comments powered by Disqus

© Anis Alekic 2020