You probably use SSH to connect to remote machines for admin purposes. Generally speaking, SSH is quite easy to use. Open your macOS terminal app and issue a command like:

ssh 192.168.1.20

As long as your usernames are the same on both ends, you’re good to go. But if your usernames aren’t the same, that command might look like:

ssh vega@192.168.1.20

Now, what happens if you remote into 10 or 20 different machines throughout the day, each with different usernames and IP addresses? That can get a bit confusing after a while. What if I told you that SSH can use a configuration file to make it much easier? By making use of the SSH configuration file, you can configure an entire data center worth of SSH connections such that you could issue a command:

ssh web1

Or:

ssh db1

How do you do that on macOS? Let me show you.

SEE: Use TechRepublic Premium’s identity theft protection policy.

Tools needed

The only thing you’ll need is a MacBook or iMac that includes SSH and some remote servers to connect to. With those at the ready, let’s make this happen.

How to create the config file

Step 1: Change SSH directory

The first thing you need to do is to change your user SSH directory.

To do this:

  1. Open the macOS terminal app.
  2. Next, change into your user SSH directory with the command:
    cd ~/.ssh

Step 2: Create new file

You will now need to create the first configuration.

  1. In the directory you changed in the step above, create the new file with the command:
    nano config
  2. Next, create your first configuration. For example, say this is a Nextcloud server at IP address 192.168.1.20 and the username is ‘vega’. We’re going to name this server ‘nextcloud,’ so we can easily remember how to Secure Shell into it. We’re also going to enable key authentication for the connection. This configuration will look like:
    Host nextcloud
    HostName 192.168.1.20
    User vega
    IdentityFile ~/.ssh/id_rsa
  3. If you’re not using SSH KEY authentication (which you should), you’ll need to remove the IdentityFile line.
  4. Save and close the file.

Step 3: SSH into server

  1. To SSH into our Nextcloud server, you’ll only have to type the command: ssh nextcloud
  2. Next, create a configuration in that file for every server in your data center, each with different options. At a minimum, you need the Host and Hostname options. For example, let’s say you use the same account on all of your data center servers on the IP address scheme 192.168.1.x. You could configure that at the top of the config file with two simple lines:
Host 192.168.1.*
User USERNAME

Where USERNAME is the user on the remote machines.

  1. Then, create each host configuration entry below that, leaving out the User option, like so:
Host nextcloud
HostName 192.168.1.20
IdentityFile ~/.ssh/id_rsa

Host web1
HostName 192.168.1.25

Host db1
HostName 192.168.1.100
IdentityFile ~/.ssh/db_rsa.pub
  1. Save the file, and you’re ready to SSH into those machines with commands like:
ssh nextcloud
ssh web1
ssh db1

And that’s all there is to creating an SSH config file to be used on macOS.

Subscribe to TechRepublic’s How To Make Tech Work on YouTube for all the latest tech advice for business pros from Jack Wallen.

Subscribe to the Cybersecurity Insider Newsletter

Strengthen your organization's IT security defenses by keeping abreast of the latest cybersecurity news, solutions, and best practices. Delivered Tuesdays and Thursdays

Subscribe to the Cybersecurity Insider Newsletter

Strengthen your organization's IT security defenses by keeping abreast of the latest cybersecurity news, solutions, and best practices. Delivered Tuesdays and Thursdays