How to change the default SSH port in Mac OS X

I made this tutorial using Mac Os X 10.6.8 (Snow Leopard).

In this example, let’s say you want to change the default port 22 to port 2222

  1. Open the terminal window
  2. Enter:
    sudo nano /etc/services
  3. Enter the root password, it will open the ‘services’ file. Be careful to avoid modify anything else.
  4. Press CTRL+W and search “ssh”.
  5. You will find to lines assigned to port 22. Something like this:
    ssh 22/udp # SSH Remote Login Protocol
    ssh 22/tcp # SSH Remote Login Protocol

    Change the number 22 in both cases to 2222 or whaterver the port you want to use. Press CTRL+X and then enter ‘Y’ to accept saving the file.

  6. Now we need to restart SSH. Enter the following command to stop it:
    sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
  7. Now enter the following command to start SSH again:
    sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
  8. That’s it, you must be ready to go. You can verify if is working by trying to access locally, just enter:
    ssh localhost -p 2222
This entry was posted in How to's and tagged , , , . Bookmark the permalink.