Login to a remote SSH server with public/private key authentication

From Cosmin's Wiki

Jump to: navigation, search

Home > Linux how to's > Login to a remote SSH server with public/private key authentication


Here's the setup: you have a server (Debian in my case), call it Server1, which is configured to accept only access with public/private key authentication. I also use a custom port for ssh (how to set this up is explained here: Secure your SSH server with Public/Private key authentification). Now, you are logged on another Debian box (Server2) and you would like to ssh to Server1.

To do this, you need to copy you private key (id_rsa or whatever you called it - I have called it cosmin.priv) to you .ssh folder. Set the appropriate rights for this file, so that only you have access to it:

> chmod go-rwx cosmin.priv

Once this is done, all you need to do is :

> ssh -i ~/.ssh/cosmin.priv -p port_num cosmin@Server1

You will be prompted for the password of the key file and, if correctly entered, you will be logged in as 'cosmin' onto Server1. That's all there is to it.