[ad_1]
Jack Wallen shows you how to make SSH connections to your macOS machine even easier.
You probably use SSH to connect to remote machines for admin purposes. Generally speaking, using SSH is fairly easy. 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 sides, you’re good to go. But if your usernames are not the same, that command might look like this:
ssh vega@192.168.1.20
Now, what if you remote into 10 or 20 different machines throughout the day, each with different usernames and IP addresses? It can get a bit confusing after a while. What if I told you that SSH can use a configuration file to make this much easier? Using an SSH configuration file, you can configure an SSH connection to an entire data center, so you can issue a command:
ssh web1
Or:
ssh db1
How do you do this on macOS? let me show you.
Look: Use TechRepublic Premium’s Identity Theft Protection Policy.
necessary equipment
All you’ll need is a MacBook or iMac that includes SSH and some remote servers to connect to. Those who are ready, let’s make it possible.
how to create config file
Step 1: Change SSH Directory
The first thing you need to do is change to your user SSH directory.
To do this:
- Open the macOS Terminal app.
- Next, change to your user SSH directory with the command:
cd ~/.ssh
Step 2: Create New File
Now you have to create the first configuration.
- In the directory you changed in the above step, create new file with the command:
nano config
- Next, create your first configuration. For example, let’s say it’s 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 it. We are also going to enable key authentication for the connection. This configuration would look like this:
Host nextcloud HostName 192.168.1.20 User vega IdentityFile ~/.ssh/id_rsa
- If you’re not using SSH key authentication (which you should be doing), you’ll need to remove the IdentityFile line.
- Save and close the file.
Step 3: SSH into the Server
- To SSH into our Nextcloud server, all you need to do is type the command: ssh nextcloud
- Next, create a configuration in that file for each server in your data center, with different options for each. 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 can configure this with two simple lines at the top of the configuration file:
Host 192.168.1.* User USERNAME
where USERNAME is the user on the remote machines.
- Then, except for the user option, create each host configuration entry below that, 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
- Save the file, and you’re ready to SSH into those machines with the command:
ssh nextcloud ssh web1 ssh db1
And that’s all to create 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.










