amazon media file explorer download upload index folder image licenses menu widget Play Pause profile-settings more dots-two-horizontal dots-two-vertical more-vertical pending google-plus hangouts facebook instagram whatsapp spotify telegram twitter vine renren rss youtube twitch vimeo flickr dribble behance deviantart 500px steam github soundcloud skype reddit linkedin lastfm delicious stackoverflow pinterest xing flattr foursquare yelp World

Simplifying SSH Connections With a Config File

One issue I have when I am connecting to my remote servers is that I manually type the server I am connection to by hand, for example
What if you could simplify the above to:

ssh username

Easy peasy!

In this guide, you will learn how to simplify ssh connections with a config file.

The way this works is you create a configuration file for servers that you connect to often, this way, ssh knows your server and can automatically pull the info when you reference it by a name.

Go ahead and open up your config file in a text editor:

sudo nano ~username/.ssh/config

The tilde (~) is referencing the username home directory.

If you don't have the config file, the command would automatically create one as long as you have the .ssh directory.

The config file is a per-user configuration file, and since you would be adding your server ssh configuration in this file, you are highly recommended to create strict permission: read/write for the user, and not writable by others (I would show you how to do this in a moment).

Also, it may be group-writeable provided that the group in question contains only the user. Back to the config file, let's create a read & write permission for the user, in my case the file is own by root:

-rw-r--r-- 1 root   root    137 Feb 29 20:11 config

Change the group and user to the username that should access the config file:

sudo chown username:username config

This would change both the user and group of the config file to the username you specify.

I want to make the config file only readable and writeable by the user, this way no other user can access, use the following command:

sudo chmod 600 config

You can learn more on Permissions on Files & Directories

Now, go ahead and structure the config file this way:

host serverA
     Port 45
     User userserver_a

host serverB
     Port 22
     User userserver_v

In the above example, I have 2 hosts outlined, serverA & serverB. I identified a way to reach serverA by its IP address and serverB by its fully qualified domain name, you can use whatever soothes you, it just makes much sense to use the FQDN (Fully Qualified Domain Name), this way, even if you change your IP address, you'll still be able to connect as you aren't relying on IP addresses.

Back on track..

Now, if I want to connect to serverA, I'll do

ssh serverA

It is as simple as that.

I should also mention that the host (the first line) can be anything, I might decide to name it baby1 and it would still connect as long as you fill in the user.

That is it about simplifying ssh connections with config files, see you later ;)


Related Post(s)

  • How To Access Windows 10 Drive/Folder in VirtualBox

    To access Windows drive or folder in your Guest OS, you first of all, install VirtualBox guest utilities: sudo apt-get install virtualbox-guest-utils You then Add a shared folder by going into: Setti

  • Send Mail with Attachment Using Mutt in GNU/Linux

    Mutt is a powerful text-based mail client for Unix/Linux operating systems. It features color support, message threading, MIME support...

  • Using Pageant To Automatically Authenticate SSH key in Putty

    I can't count how many times I have typed my ssh key passphrase whenever my ssh connection times out, it is so annoying and repetitive. Well, thanks to the putty pageant, you can do that seamlessly.

  • Installing WP-CLI In a GNU/Linux Server

    WP-CLI is a command-line interface for WordPress. It can also be used with ClassicPress, as they are no differences in their usage, maybe just minimal if you are updating or downloading new ClassicPr

  • How To Send Mail To Multiple Addresses Using (mailx)

    In this guide, you'll learn a couple of ways you can send mail to multiple addresses using mailx. mailx is a utility program for sending and receiving mail. I assume you already have mailx command, i

  • Mounting and Unmounting Cloud Storage With (Rclone) in GNU/Linux

    Ever wondered if you could mount your preferred cloud storage as a virtual drive on your system? Thanks to Rclone, you can mount and access different kinds of cloud storage from a file manager, I'll