Categories
Tutorials Workflow

Making SSH logins super-quick

SSH access is pretty essential these days in web development. Especially if you have root access to a server, or using tools like Grunt, Git or Sass. But signing into them can be very time consuming.

I just recently put together a straightforward workflow (OSX and Linux) for logging into a server via SSH.

Using an SSH Config file

The SSH Config file saves your usernames, hosts and ports into a single config file.

  1. If the config file isn’t there, create it by running these commands:
    $ mkdir ~/.ssh # this directory may already exist
    $ vim ~/.ssh/config
  2. Now you can edit this file and add the following code for each server you want to connect to:
    Host ryan
        HostName ryantvenge.com
        Port 22 #The default port for SSH.
        User user_name
  3. Now, you can simply type ssh ryan to connect to the server.

Creating SSH Keys

But it is still asking for your password. So let’s get rid of that step too by creating an SSH key. SSH keys are a great tool to secure access to servers. It gives you the ability to use super-secure passwords because you don’t have to remember them. But they are kind of a pain to setup.

Run the following comands:

$ ssh-keygen -f ~/.ssh/ryan -C "ryan"
$ ssh ryan 'mkdir ~/.ssh && touch ~/.ssh/authorized_keys #these files may already exist, so you may get an error. Don't worry
$ cat ~/.ssh/ryan.pub | ssh ryan 'cat >> .ssh/authorized_keys'
  1. The first command creates the key. For simplicity’s sake, I named the key the same name as our SSH config shortcut name, “ryan”. When asked for a passphrase, simply hit return twice.
  2. The second command is creating a spot on the server to hold your ssh key.
  3. The last command copies your public key up to the server.

And Bob’s your uncle, you are all done! No more typing passwords in when pushing and pulling Git repos. No more forgetting IP addresses of servers. And best of all, you can now make your passwords sooper secure 50 character random strings, because you won’t need to type time in manually on a regular basis.

Update: If you are using git, you’ll need to update your remote path with the shortcut name, otherwise it won’t use your ssh key:

url = ssh://SHORTCUT_NAME/path/to/git/repo

By Ryan Tvenge

I'm a web developer and co-owner of Hoverboard that makes cool stuff on the web.

Leave a Reply

Your email address will not be published. Required fields are marked *

Tvenge Design