MacOS – Change ssh connection info for Remote Login

mac-minimacossshterminal

I've been setting up an array of Mac Minis running Sierra, and I'm trying to be consistent about naming them.

However, for some reason, some of their ssh name@hostnames are different.

For example, the Computer Name and account names are all consistent, eg: Mini Kiosk 02 "mini-kiosk-02".

But their ssh info is sometimes different.

Some are "ssh mini-kiosk-02@mini-kiosk-02" while others are "ssh mini-kiosk-04@mac-mini".

I'm not seeing how I can change, eg, the part after the @ sign.

I thought scutil --set HostName etc might do the trick, but that doesn't seem to change anything.

Update

As you can see from the screenshot, hostname does not seem to correspond to what is after the @ in the Remote Connection settings.

Screenshot showing terminal window after hostname command showing "mac-mini" as hostname, with Sharing dialog open showing ssh mini-kiosk-02@mini-kiosk-02" in the Remote Login settings

Best Answer

Your command should work:

sudo scutil --set HostName YourHostName

Since OSX 10.9 Maverick, it's possible to change it with hostname command. Without -s it will be a temporary change, adding the -s will set it up permanently:

sudo hostname -s YourHostName

To verify it, you may type hostname and observe the return.

Update

OSX uses different variables to name the machine. You may need to reset them as well.

scutil --set HostName YourHostName
scutil --set ComputerName $(hostname -s)
scutil --set LocalHostName $(hostname -s)
defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string $(hostname -s)