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
- Open the terminal window
- Enter:
sudo nano /etc/services - Enter the root password, it will open the ‘services’ file. Be careful to avoid modify anything else.
- Press CTRL+W and search “ssh”.
- 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.
- Now we need to restart SSH. Enter the following command to stop it:
sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist - Now enter the following command to start SSH again:
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist - 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
I have been trying to change the ssh to 2222 as you suggest; alas it seems not to be working. When I save the changes, open a new window to restart ssh it gives me:
:~ applemac$ sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
:~ applemac$ sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
:~ applemac$ ssh localhost -p 2222
ssh: connect to host localhost port 2222: Connection refused
:~ applemac$
Hi,
Mjmm… ok.
1. Did you edit the /etc/services file as indicated – If not, that is a must
2. I wonder what version of OS X do you have? Maybe there we can find an answer too. Also can you provide me with the result of entering the following command?:
uname -a
3. Finally, if you have a firewall software… something like Little Snitch installed. You should authorize the traffic throught the chosen port.
BTW, I tried the method with the latest Snow Mountain Lion and works well too.