This is simple. Open a terminal and follow the steps below. This worked for me on MacOS 10.13.6

  • Open the Terminal.
  • Run sudo vim /etc/services
  • Enter your password
  • Find the lines assigned to port 22, something like the image below

Replace both ports 22 with your desired ssh port using a number between 1024 and 32,767

Now you need to restart the services. Be sure to do this if you have direct console to the mac. If you do it remotely you may loose connection. I could not find a way to ‘restart’ a service on MacOS as we normally do in Linux. You have to ‘unload’ and ‘load’ the service in MacOS. Use the below commands.

sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

Now you can SSH using:

ssh <youruser>@<yourHostOrIP> -p <yourNewPort>
For example: ssh john@localhost -p 18765

Leave a comment

Your email address will not be published. Required fields are marked *