I'm mostly a Linux user. And I tend to have the same username on my desktops as I do on my servers. That means most of my SSH commands are in the form:
ssh 192.168.1.100
I've been using SSH for a very long time, and that habit is pretty much ingrained in me.
However, when I'm on my MacBook or iMac, those usernames don't tend to be the same as my Linux servers. This means that command then turns into something like this, where Username is the username on the remote server:
ssh [email protected]
Okay, that's not a huge difference, and adding a username to the command doesn't take that much extra time. However, when you're in and out of servers all day, that time adds up. On top of which, when you realize (for the tenth time that day) you've forgotten to add the username to the SSH command, it can be frustrating to have to [Ctrl]+[C] out of the command and retype.
Also: Don't waste your money on these Apple products
Fortunately, there's a way around that. With SSH, there's a user-specific config file that allows you to set a default username for all of your SSH connections. In that configuration file, you can create entries for individual connections. An individual entry might look something like this:
Host ubuntu-invoice User jack Hostname 192.168.1.100 IdentityFile ~/.ssh/id_rsa
In the above configuration, the following options are explained:
You can set up individual entries for every remote machine you connect to via SSH in this way, and it doesn't matter how many entries you add to the file. On top of that, every entry can have different options.
However, we're talking about setting a default username for all of your connections. Once you've set this option, any time you issue an SSH command without a username, it will assume what is set as the default in the config file is the username to apply. However, if you have individual entries that include a username, those entries will preempt the default.
Also: The 6 best Macs
What do I mean by that? Let's say you set the default SSH username in the config file to jack. Also, in the config file, you have this entry:
Host microk8s User olivia Hostname 192.168.1.70
If you issue the commandssh microk8s, SSH will apply the olivia username to the connection.
Let's get this configuration up and running.
The first thing to do is open the Terminal app. To do this, click the Launchpad in the MacOS Dock and search for and click to open the Terminal app.
From the Terminal window, open the configuration file for editing with the command:
nano ~/.ssh/config
At the top of the file, you'll add an entry like this, where Username is the user you want to configure:
Host * User USERNAME
Once you've added that entry, save and close the file with the [Ctrl]+[X] keyboard combination.
Also: The basics of SSH usage
Now, when you go to connect to any server via SSH, you can leave out the username in the command. Of course, if the remote username is different than the default you've configured, simply add it to the command, bypassing the default configuration.