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 access to the console for your MacOS. 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

Hope this small post was useful. If you like to learn more about MacOS you can grab this book MacOS and iOS Internals, Volume I: User Mode (v1.3)

Join the Conversation

2 Comments

  1. Good grief, thank you. Spent too much time trying csrutil disable/enable and editing /System/Library/LaunchDaemons/ssh.plist. None of these features worked. SIP would always get in the way.
    Your method was so simple and ‘just worked’.
    This worked for me on macOS Big Sur 11.5.1

Leave a comment

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