I, for some reason, cannot seem to find a google search which actually answers this question. I have a mac, and I would like to have the ssh daemon running in the background at all times, so I can ssh in from other machines whenever I need to. Currently, I can enable ssh by going to System Preferences > Sharing > Remote Login, and checking the box to turn on the service. I am able to ssh in successfully. However, after enabling it, the ssh service automatically disables itself after I disconnect from my ssh session. I enable the service through mac, connect via ssh from another machine, disconnect, and then check the mac settings to find ssh disabled. Additionally, I believe my mac will automatically terminate ssh after a period of time, either from the machine going to sleep, or from a timeout, I haven't figured out the trigger yet.
How can I make it so the ssh daemon is PERMANENTLY enabled? I want the equivalent of systemctl enable sshd
for mac. I want the ssh daemon to start on boot, and remain running while the machine is on without timing out or shutting down when a user disconnects.
I am currently running MacOS Monterey 12.6
EDIT: To clarify based on comments received, I can login via ssh if I enable Remote Login in system preferences. This is the default ssh that was installed when I received the Mac, and I do not believe there is any MDM software installed on the Mac other than Computrace. My account is an admin, as Remote Login is restricted to only allow Administrators, and I have sudo access as well.
I have done some more testing and I cannot seem to reliably reproduce the issue where Remote Login disables itself after I connect and disconnect over ssh, but it has for a fact happened. Just prior to posting this question, I enabled Remote Login via system preferences, connected to the mac via ssh, closed that connection, and then checked via system preferences again to find Remote Login no longer checked.
It seems in addition to randomly turning off the Remote Login service is disabled when the Mac goes to sleep. I have had an ssh session get disconnected before, but I wonder if perhaps that was a separate issue, perhaps a wifi mishap as I was just now able to connect over ssh, and then while connected, disable Remote Login without terminating the existing ssh connection.
Thank you for the tip about launchctl. I can see via launchctl now that sshd creates a new process when a connection is attempted. However, when Remote Login is disabled, or becomes disabled of it's own accord, the com.openssh.sshd process is not existant, and therefore does not create a subprocess to handle the connection.
% sudo launchctl list | grep ssh
- 0 com.openssh.sshd
90388 0 com.openssh.sshd.43C47EF8-F4FF-49E2-BBD9-96D87190B91B