Accessing a Remote Server Via SSH

Step 1: Generate a key pair

First, log in to the local machine and generate a public/private key pair. I used puttygen.exe. Now store the newly-generated keys on the local machine.

Step 2: Install openSSH

Next, log in to the server you want to access remotely, then find your way to the command line. Now update the repositories and install the SSH server as follows:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install openssh-server

Step 3: Install the public key

From inside the logged user’s home directory, type following commands:

mkdir .ssh
nano .ssh/authorized_keys

Now copy the public key into the authorized_keys file on a single line, save the file, and type the following commands to make sure that permissions and ownership are set properly:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
chown $USER:$USER ~/.ssh -R

Step 4: Update the SSH configuration

Navigate to /etc/ssh, open sshd_config, and edit the settings to reflect the following:

RSAAuthentication yes
PubkeyAuthentication yes
ChallengeResponseAuthentication no
PasswordAuthentication no
UsePAM no
AuthorizedKeysFile %h/.ssh/authorized_keys

Step 5: Restart the server

Now restart the server and confirm that SSH is running properly:

sudo service ssh restart
sudo service ssh status

For troubleshooting help, type sudo tail -f /var/log/auth.log.

Step 6: Connect from the local machine

Finally, go back to the local machine and configure PuTTY (or whatever) to make the connection.

@note: For a slightly different approach, check out Martin’s Blog – Setting Up SSH.