Magisk-Modules-Repo / ssh

ssh
177 stars 34 forks source link

stale sshd.pid prevents start #11

Open Bushmills opened 5 years ago

Bushmills commented 5 years ago

Possibly the cause of other posts related to "sshd not running": Especially after installing updates of ssh for Magisk did sshd fail to start on next device boot. The cause has been found to be a stale /data/ssh/sshd.pid file. After deleting that file manually, sshd will run on next boot, and can alternatively be manually launched by executing opensshd.init Path of opensshd.init doesn't match the path specified in the instructions. This may be due to Magisk hidden on my system. I find it it here: /sbin/.magisk/img/ssh/opensshd.init My workaround for the pid problem is now to let shutdown trigger execution of rm -f /data/ssh/sshd.pid

D4rCM4rC commented 5 years ago

Thanks for the hint about the wrong opensshd.init path in the README. I'll update that in the next version.

Unfortunately I cannot reproduce your problem. sshd never fails to launch on my device. I don't think sshd even cares about an existing pidfile. It will just overwrite it, if it exists (https://github.com/openssh/openssh-portable/blob/master/sshd.c#L1925).

The only thing I could imagine (especially as you mentioned updates), are messed up permissions in the /data/ssh directory. Could you try to reproduce the problem and then check permissions and owners of this directory and the pidfile?

Bushmills commented 5 years ago

Ok, I've removed removal of /data/ssh/sshd.pid from shutdown event, now I'm waiting for upgrades. Concerning permissions: though I didn't look at those, I also didn't modify them in order to get sshd running again. Looking at opensshd.init, it indeed doesn't care about a stale sshd.pid. sshd docs say it will contain the pid of the last started server in case several are launched - which implies overwriting and not caring about an existing pid file. While the device is now in a state again that sshd is launched again after boot, I can only report from memory: sshd not starting happened not only with one single upgrade, but with at least two upgrades. When it wouldn't start, it wouldn't do so regardless how often the device was booted. This made me initially believe that the upgrade was broken, und I consequently uninstalled ssh for Magisk. I think I then tried to reinstall a previous version of ssh for Magisk, which failed to launch as well. At what time I reinstalled again later, I can't say for sure, nor whether in the meantime a new version of custom ROM (lineage OS) was installed, but quite likely it was. Anyway were conditions then such that sshd started again. After a later upgrade, it again failed to launch, which was when I set out to examine possible reasons for failure - which I then believed to have found in the stale sshd.pid, because after noticing it's presence while sshd wasn't running, and subsequent deletion, sshd started again. Next time this happens, I'll take a better look at permissions of involved files and directories. To make sure that a stale pid file isn't part of the problem, it could be created in volatile memory.

Bushmills commented 1 year ago

That didn't happen again since. It must have been a glitch of some kind, or some other condition preventing sshd to start which was somehow removed by accident while I was trying to figure out the problem cause, then I made the change of my last action responsible. Working/autolaunching sshd on Android is best thing since sliced bread!