DEV Community

Aaron Dunphy
Aaron Dunphy

Posted on • Updated on • Originally published at aarondunphy.com

How to Setup Quick SSH Access

In this article you will learn how you can set up a quick and easy way to SSH onto any server without needing to remember the user or IP address. This will work by running a command similar to:

ssh server_name
Enter fullscreen mode Exit fullscreen mode

Machine Setup

Check if your machine already has a public SSH key generated:

cat ~/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

If you see “No such file or directory” then generate a SSH key otherwise skip this step (click enter at all prompts):

ssh-keygen
Enter fullscreen mode Exit fullscreen mode

Edit the SSH config file to setup quick SSH access to a server from your local machine:

sudo nano ~/.ssh/config
Enter fullscreen mode Exit fullscreen mode

Ensure all hosts use key chain is at the top of the file:

Host *
     UseKeyChain yes
Enter fullscreen mode Exit fullscreen mode

Then you can insert as many host references as you would like. Insert the following (changing the server_name, ip_address and server_user):

Host server_name
     HostName ip_address
     User server_user
     IdentityFile ~/.ssh/id_rsa
     IdentitiesOnly yes
Enter fullscreen mode Exit fullscreen mode

Copy your machine's ssh public key:

cat ~/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode

Server Setup

Add your machine's SSH public key to the server's authorized_keys file (you will need to SSH onto the server with ssh user@ip first):

sudo nano ~/.ssh/authorized_keys
Enter fullscreen mode Exit fullscreen mode

You can then ssh on via

ssh server_name
Enter fullscreen mode Exit fullscreen mode

Top comments (0)