This is simple. Open a terminal and follow the steps below. This worked for me on MacOS 10.13.6. Also, brew a great cup of coffee at home for inspiration.
- 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)
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
I’m glad it works for you. Cheers…
Thank you. It works for me on MacOS Monterey v12.4
I’m glad it works for you. Thanks!
I got this working, but here is the problem. After you reboot your Mac remotely, the ssh server doesn’t work anymore. You need to login to your Mac on the actual machine start the ssh server.
Is there any workaround to login to SSH after a Mac reboot ?
Hello Jerome,
Sorry for the late reply. I have not experience this problem. If you have ‘Remote login’ enabled in your System Preferences>Sharing it should always work not matter if you reboot. What’s your macOS version? Thank you for the feedback…
Thanks so much for this! I had never wanted to deal with SIP (because you have to go through it after every macOS update), or any of the other convoluted solutions I found online (eg. winding up a second SSHd instance). But this works perfectly in macOS Ventura 13.0 RC2, and is very easy to implement with a sudo sed command (since the services file will likely be overwritten with every macOS update).
For restarting the SSH server, the following commands may be better, as they will start the Remote Login service if the user hasn’t enabled it:
sudo systemsetup -f -setremotelogin off
systemsetup -f -setremotelogin on
Phong, glad this worked for you. Thanks.