X
Tech
Why you can trust ZDNET : ZDNET independently tests and researches products to bring you our best recommendations and advice. When you buy through our links, we may earn a commission. Our process

'ZDNET Recommends': What exactly does it mean?

ZDNET's recommendations are based on many hours of testing, research, and comparison shopping. We gather data from the best available sources, including vendor and retailer listings as well as other relevant and independent reviews sites. And we pore over customer reviews to find out what matters to real people who already own and use the products and services we’re assessing.

When you click through from our site to a retailer and buy a product or service, we may earn affiliate commissions. This helps support our work, but does not affect what we cover or how, and it does not affect the price you pay. Neither ZDNET nor the author are compensated for these independent reviews. Indeed, we follow strict guidelines that ensure our editorial content is never influenced by advertisers.

ZDNET's editorial team writes on behalf of you, our reader. Our goal is to deliver the most accurate information and the most knowledgeable advice possible in order to help you make smarter buying decisions on tech gear and a wide array of products and services. Our editors thoroughly review and fact-check every article to ensure that our content meets the highest standards. If we have made an error or published misleading information, we will correct or clarify the article. If you see inaccuracies in our content, please report the mistake via this form.

Close

How to set an SSH username in MacOS

If you use Secure Shell on MacOS and want a more efficient way of running those SSH commands, there's a very easy way to set your username to simplify remote connections.
Written by Jack Wallen, Contributing Writer
Reviewed by Min Shin
Two people using MacBook Pro
Apple

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 USERNAME@192.168.1.100

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:

  • Host: The nickname used for the connection (so you could connect with simply ssh ubuntu-invoice).
  • User: The username for the connection.
  • Hostname: The IP address or domain for the connection.
  • IdentityFile: If you use SSH key authentication, this defines the key file used.

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 command ssh microk8s, SSH will apply the olivia username to the connection.

Let's get this configuration up and running.

How to set up an SSH username in MacOS

1. Open the Terminal app

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.

2. Open the SSH config file for editing

From the Terminal window, open the configuration file for editing with the command:

nano ~/.ssh/config

3. Add the User entry

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.

Editorial standards