RE: SSH nonstandard ports under Mac OS X...
If you happen to still have a router that does not support forwarding ports to different port numbers, then you could also just change the ssh port on your Mac itself by editing /etc/sshd.conf and adding a 'Port XXXX' statement in there (and restarting), and setting up a straight forward on your router.
Hi Beerfloat,
I believe Apple is slowly getting away from the standard Unix/Linux
/etc/sshd.conf and
/etc/ssh.conf configuration files.
(You could download and compile your own ssh package, say from MacPorts, and then it would work with sshd.conf and ssh.conf and you could easily change the default port 22 to anything you want, say 10022.) But the Mac OS X's ssh server/client now default to using a property list for their configuration. This means that if you use the Mac OS X's ssh, then you will configure it by a slightly different way. The following shows how this is done.
SSH Server
On the SSH server, call it
myserver.private, edit the
/etc/services file to add a new service, say "ssh-nonstd". It turns out that port 10022 is not already assigned to a service, so we'll use this port. The following lines are added to the
/etc/services file (and I would add them so that the ports numbers are properly sorted):
/etc/services
Code:
# Adding nonstandard ports for sshd on myserver.private:
ssh-nonstd 10022/tcp # non-standard ssh port for myserver.private
ssh-nonstd 10022/udp # non-standard ssh port for myserver.private
After editing the
/etc/services file, adding the above lines, we now must edit the property list file to reflect the change in service. Thus edit the file:
/System/Library/LaunchDaemons/ssh.plist
on
myserver.private using a plist editor, like "TextWrangler", to change the SockServicesName to ssh-nonstd. In other words, find the following lines:
/System/Library/LaunchDaemons/ssh.plist
Code:
<key>SockServicesName</key>
<string>ssh</string>
and edit them to read:
Code:
<key>SockServicesName</key>
<string>ssh-nonstd</string>
You must now relaunch the ssh daemon on
myserver.private (or reboot the
myserver.private machine):
Code:
launchctl unload /System/Library/LaunchDaemons/ssh.plist
launchctl load /System/Library/LaunchDaemons/ssh.plist
You now have a sshd daemon running on port 10022 on
myserver.private.
Note: You can use different nonstandard ports for different machines on your LAN, this would then allow you to ssh to different machines just by changing the port number. So port 10022 would be for myserver.private, while port 10023 might be for your MacBook Pro: myMBP.private.
Router
You must now configure your router to forward ports 10022/tcp and 10022/udp to your server (use the private LAN IP address of
myserver.private, say 192.168.0.10 or whatever you use to do this port forwarding on your router) ports 10022/tcp and 10022/udp.
Let's also say the Internet URL for your router is either
myinterneturl.myhome.net, or if you don't use a domainname, say your router has an Internet IP address of
212.63.218.101, for example.
SSH Clients
Next I would setup aliases on your client machines to automatically ssh to the proper nonstandard 10022 port. You would add the following lines to your
~/.bashrc file or your
~/.bash_profile file:
~/.bashrc
Code:
alias myserversshlocal='ssh -p 10022 yourusername@myserver.private'
alias myserverssh='ssh -p 10022 yourusername@myinterneturl.myhome.net'
or, if you don't run your own DNS server and don't have an Internet domain name, then
Code:
alias myserversshlocal='ssh -p 10022 yourusername@192.168.0.10'
alias myserverssh='ssh -p 10022 yourusername@212.63.218.101'
If your client machine is on your local network, then you ssh to your server using the alias:
or if your client machine is on the Internet, then you ssh to your server using the alias:
Or if you don't define the aliases in
~/.bashrc, then you would ssh to your
myserver.private (local) or
myinterneturl.myhome.net (Internet) using the "-p" option:
Code:
ssh -p10022 yourusername@myserver.private
ssh -p10022 yourusername@myinterneturl.myhome.net
or, without DNS names, then use the "-p" option for the local and Internet ssh:
Code:
ssh -p10022 yourusername@192.168.0.10
ssh -p10022 yourusername@212.63.218.101
SSH Tunnels
If you are also using ssh for tunneling other services, then you must reconfigure them to use the nonstandard ports. For instance, say you are using an ssh tunnel for a subversion repository on
myserver.private. Then in the
~/.subversion/config file on your client, specify the new port for the ssh tunnel:
~/.subversion/config
Code:
[tunnels]
ssh = $SVN_SSH ssh -p 10022
This will allow you to perform your "svn commit"s using normal subversion commands, for example:
Code:
svn commit -m "Updating the Ricci rotation coefficients of the Christoffel module"
even though this is being piped through the nonstandard port 10022 ssh tunnel.
Or if you are using "rsync" for differential backups from
myserver.private to your client machine through a ssh tunnel, then you would use the following "rsync" command with the "--rsh=" option for the tunnel (for example):
Code:
rsync --rsh='ssh -p10022' -avz 'myserver.private:/Shared\ Items/Repos/Repos' /Volumes/SCMyPassport/Repos
to backup the repos directory on
myserver.private to an attached USB3 drive, SCMyPassport, on your client machine.
Sorry for the length of this posting, but I just wanted to specify exactly what needs to be done in order to switch to nonstandard SSH ports under the Mac OS X and then switch your SSH tunnels also to the nonstandard ports.
Have fun with your nonstandard SSH.
Regards,
Switon
P.S. I know that Beerfloat's posting is several years old, that is why I decided to describe the latest plist way of configuring SSH under Mac OS X instead of the older sshd.conf method.