Inscrivez-vous maintenant pour un meilleur devis personnalisé!

Nouvelles chaudes

How to set an SSH username in MacOS

17 janv. 2023 Hi-network.com
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

More how-tos

  • How to set up and use Meta's Threads as a Windows 11 desktop app
  • 3 essential Windows tools for troubleshooting (and how to use them)
  • How to use iOS 17's 'Live Voicemail' transcriptions, and which iPhones support it
  • Bing Chat now has the highly-requested dark mode. Here's how to turn it on

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:

  • Host:The nickname used for the connection (so you could connect with simplyssh 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 commandssh 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.

Apple

This powerful app tells you everything about your iPhone, iPad, or MacBook's batteryI can't recommend the 15-inch MacBook Air enough, even if it's not for meApple Watch upgrade time? How to choose between Series 8, Ultra, or waiting for Series 9I tried Apple Vision Pro and it's far ahead of where I expected
  • This powerful app tells you everything about your iPhone, iPad, or MacBook's battery
  • I can't recommend the 15-inch MacBook Air enough, even if it's not for me
  • Apple Watch upgrade time? How to choose between Series 8, Ultra, or waiting for Series 9
  • I tried Apple Vision Pro and it's far ahead of where I expected

tag-icon Tags chauds: Services et logiciels Systèmes d’exploitation Sous Mac OS

Copyright © 2014-2024 Hi-Network.com | HAILIAN TECHNOLOGY CO., LIMITED | All Rights Reserved.
Our company's operations and information are independent of the manufacturers' positions, nor a part of any listed trademarks company.