Quantcast
Channel: VPS.NET Public Knowledge Base » Getting Started
Viewing all articles
Browse latest Browse all 10

Creating SSH Host Shortcuts

0
0

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.


Viewing all articles
Browse latest Browse all 10

Latest Images

Trending Articles





Latest Images