Friday, December 19, 2014

SSH Daemon on a Mac

A Mac is a weird thing that doesn't always know whether it wants to be BSD or Linux.

Here is the magical incantation to start a SSH Server:
$ sudo launchctl start /System/Library/LaunchDaemons/ssh.plist

One can then check it with a Telnet client:
$ telnet localhost ssh 
 Trying ::1... 
 Connected to localhost. Escape character is '^]'. 
 SSH-2.0-OpenSSH_6.2 ^] 
 telnet> q 
 Connection closed. 

Now you can use scp and ssh from another machine on the LAN, but one needs to know what the IP address is:
$ ifconfig en0 | grep inet 
inet6 fe80::5626:96ff:fece:371f%en0 prefixlen 64 scopeid 0x4 
inet 192.168.1.5 netmask 0xffffff00 broadcast 192.168.1.255


Run SSHD On A Different Port

If you want to allow internet access to your Mac and don't want to be bothered by script kiddies all the time, then you need to change sshd to a different port. 

The Mac launchctl system seems to ignore the /etc/sshd_conf file.  The only way that I could convince it to run on a different port, was by editing the /etc/services file and then reloading sshd with launchctl.

$ sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist
$ sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist
 

This will automatically change the firewall port also. 


La voila!


No comments:

Post a Comment

On topic comments are welcome. Junk will be deleted.