Creating SSH Host Shortcuts

Creating SSH Host Shortcuts

Creating SSH Host Shortcuts

Category: Getting Started &nbsp

If you are managing a number of servers a big timesaver is anything that means you can type less to connect to the server required. This is where the SSH config file can be very helpful.  By default SSH will look for a file called config in the hidden directory .ssh in the user’s home directory. This file is a simple text file and can be edited in your text editor of choice, for an example using nano…

nano ~/.ssh/config

Let’s imagine that you have a handful of servers that you log into regularly. For some added security they are using non-standard ports and you have different users on each machine.  The kind of annoying situation you end up in when you are working with a number of different groups. Let’s look at an example situation, imagine the ssh command below…

jp@localhost:~$ ssh -p40000 johnny@testing.www.example.com

I’ve included a local prompt to aid explanation. So every time that server is connected to, the username needs specifying as it is different to the local username and the port needs specifying.

Now lets consider adding the following lines to the ~/.ssh/config file

Host test-example

    HostName testing.www.example.com

    Port 40000

    User johnny

With that added to the file, connecting would be as simple as…

jp@localhost:~$ ssh test-example

Much shorter and easier. Now let’s imagine that things are worse and you are using individual SSH keys for each server, now that’s good security practice, which adds “-i ~/.ssh/testing-example.key” to the ssh command. That can also be included in the ssh config file, making it now:

Host test-example

    HostName testing.www.example.com

    Port 40000

    User johnny

    Identity ~/.ssh/testing-example.key

Even if you are using a short and simple-to-type hostname this can be useful. If the Host line in the config matches the hostname used to connect to the server then you save a line in the config but can still pick up your other files, try this other example…

Host www.example.com

    Port 40000

    User johnny

    Identity ~/.ssh/live-example.key

You can create entries for as many different hosts as you require and it can help a lot when dealing with systems with long hostnames or no DNS assigned, saving remembering IP addresses. For me the most useful part is being able to easily manage which of my SSH keys applies to which server, which makes the time spent editing the config file well spent.

    • Related Articles

    • Creating a VPS

      To create your first Cloud Server (VPS), you will have to follow these steps: On a Dashboard under “Cloud Servers” section, choose and click on “Create new Cloud Server”: The same actions can be done from “Quick Links” section using “Create new Cloud ...
    • Creating a Geo Hosting account

      Creating a Geo Hosting account Category: Getting Started &nbsp It’s as easy as 1-2-3. You can either sign up for our Geo Hosting directly from the website or – if you already have your account with us – from your dashboard by clicking on Geo Hosting ...
    • Creating On Demand Stream Links

      Creating On Demand Stream Links Category: On Demand Streaming &nbsp Creating Links in Reverse Proxy Mode When using Reverse Proxy mode, the customer has a choice in how they create their On Demand stream links. Customers can elect to directly embed ...
    • A definition of SSH port knocking for beginners

      A definition of SSH port knocking for beginners Category: Networking &nbsp Knock, knock. Who’s there? Reading about port knocking can be as clear as diving headfirst into a bog whilst wearing a snorkel. Some people love it, but for most of us, it ...
    • How To Configure Proxy Settings

      Before getting started with proxy, read: http://varnish.projects.linpro.no/static/getting-started.html. Then, open /etc/varnish/default.vcl and begin configuring to suit your needs. To configure simple round-robin proxying of 2 webservers with the ...