Transcript
  • Servers and Tools

Using a Config File

From the class:  SSH

Having to remember all these different options for SSH each time is really cumbersome, especially if you have lots of different servers and maybe the IP addresses aren't so memorable, because they're an IP address that where assigned to you by Amazon, or DigitalOcean, or some other service provider. So we can store all of this information in a configuration file. And that'll make our life significantly easier. Let me show you how to do that.

Inside of the SSH, the .ssh folder, you can create a file called config. And any configuration options that are in there will be used by SSH automatically. So let's go ahead and create a file called config inside of the .ssh folder. And I'll open that up in Vim. You can open it up in any editor you like.

Now, inside of this configuration file, I can create different entries for different servers that I want to be able to log into. I start by typing the word Host-- capital H. And then I can give this any name I want. That's the beauty of this. I can call this Chris. I could call it VM. I could call it deployment server or deploy. Whatever I want as long as it's a unique name. Let's call this one VM just for the heck of it, because I can't think of another name.

Now I'm going to press Tab. And I'm going to provide some properties. The first one is called HostName. And the HostName property is going to be the actual address of the machine. So in this case, it's going to be 127.0.0.1. But if you are hosted on Amazon, this would be some IP address that Amazon gives you.

The next option we'll give this is a port. And in this case, the port is going to be 2222. The only time you have to provide this option is if it's not the default port, which is true, too. Otherwise, SSH will just use this by default. But since ours is non-default, we need to provide it.

The next option is going to be the username that we want to log in as. So in this case it'll be cmather. And then finally I can provide an identity file. So a path to an IdentityFile. Identity-- It's quite a mouthful to spell. And I'll provide it a path to this file id_rsa.

Now that I've got all of this in here, all I need to do is to save this file, quit out of it. And now I can say ssh vm. I can just use the host that I created. And that will be the same as providing all of those different options. So this is so much simpler, isn't it?

It's particularly simpler when we start combining all the different commands, like what we were doing previously. So if I'm trying to type something into SSH, instead of having to use all those options again, I can just say ssh vm. And then I can [INAUDIBLE] out standard input, just like I did before.

In order so I'm not having to enter in any passwords here, and I don't have to provide all these options or remember IP addresses. I just have to remember this one word, which is vm. So if you're running servers, especially if you're running more than one, this is a lifesaver. And it was one of the coolest features that someone pointed out to me that I did not know about with SSH. So definitely go ahead and use the SSH config file.

Now there's a ton of SSH options in the configuration file that I didn't have time to cover. And in order to learn about them all, you can use the man pages and search for-- or open up the man pages for SSH_config. And this will talk all about SSH client configuration files. If you scroll down, you can see some of these options that we were using, like Host and some other ones that we didn't cover. So take a look at the man pages for this if you want to learn more.