<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">On Wed, Mar 6, 2024 at 2:01 PM Lennart Poettering <<a href="mailto:lennart@poettering.net">lennart@poettering.net</a>> wrote:<br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Mi, 06.03.24 11:11, Shreenidhi Shedi (<a href="mailto:shreenidhi.shedi@broadcom.com" target="_blank">shreenidhi.shedi@broadcom.com</a>) wrote:<br>
<br>
> Hi All,<br>
><br>
> What is the rationale behind using sshd.socket other than not keeping sshd<br>
> daemon running always and reducing memory consumption?<br>
<br>
Note that there are two distinct modes to running sshd via socket<br>
activation: the per-connection mode (using sshd's native inetd mode),<br>
where there's a separate instance forked off by systemd for each<br>
connection, and the a mode where systemd just binds the socket, but<br>
it's served by a single instance. The latter is only supported via an<br>
out-of-tree patch afaik though, which at least debian/ubuntu ship:<br>
<br>
<a href="https://salsa.debian.org/ssh-team/openssh/-/commit/7fa10262be3c7d9fd2fca9c9710ac4ef3f788b08" rel="noreferrer" target="_blank">https://salsa.debian.org/ssh-team/openssh/-/commit/7fa10262be3c7d9fd2fca9c9710ac4ef3f788b08</a><br>
<br>
Unless you have a gazillion of connections coming in every second I'd<br>
probably just use the per-connection inetd mode, simply because it's<br>
supported upstream. Would be great of course if openssh would just add<br>
support for the single-instance mode in upstream too, but as I<br>
understand ssh upstream is a bit special, and doesn't want to play<br>
ball on this.<br>
<br>
To summarize the benefits of each mode:<br>
<br>
1. Traditional mode (i.e. no socket activation)<br>
+ connections are served immediately, minimal latency during<br>
connection setup<br>
- takes up resources all the time, even if not used<br>
<br>
2. Per-connection socket activation mode<br>
+ takes up almost no resources when not used<br>
+ zero state shared between connections<br>
+ robust updates: socket stays connectible throughout updates<br>
+ robust towards failures in sshd: the bad instance dies, but sshd<br>
stays connectible in general<br>
+ resource accounting/enforcement separate for each connection<br>
- slightly bigger latency for each connection coming in<br>
- slightly more resources being used if many connections are<br>
established in parallel, since each will get a whole sshd<br>
instance of its own.<br>
<br>
3. Single-instance socket activation mode<br>
+ takes up almost no resources when not used<br>
+ robust updates: socket stays connectible throughout updates<br>
<br>
> With sshd.socket, systemd does a fork/exec on each connection which is<br>
> expensive and with the sshd.service approach server will just connect with<br>
> the client which is less expensive and faster compared to<br>
> sshd.socket.<br>
<br>
The question of course is how many SSH instances you serve every<br>
minute. My educated guess is that most SSH installations have a use<br>
pattern that's more on the "sporadic use" side of things. There are<br>
certainly heavy use scenarios though (e.g. let's say you are github<br>
and server git via sshd). I'd suggests to distros to default to mode<br>
2, and alternatively support mode 3 if possible (and mode 1 if they<br>
don#t want to patch the support for mode 3 in)<br>
<br>
> And if there are issues in unit files like in<br>
> <a href="https://github.com/systemd/systemd/issues/29897" rel="noreferrer" target="_blank">https://github.com/systemd/systemd/issues/29897</a> it will make the system<br>
> unusable.<br>
<br>
Did any distro ship a unit file like that? That was clearly a buggy<br>
(local?) unit file, I am not aware of any big distro shipping such a<br>
unit file.<br>
<br>
Lennart<br>
<br>
--<br>
Lennart Poettering, Berlin<br></blockquote><div> </div><div><div class="gmail_default" style="font-size:small">Thanks a lot for the responses Andrei, Poettering .</div></div></div><div class="gmail_default" style="font-size:small">We took it from blfs in PhotonOS.</div><div class="gmail_default" style="font-size:small"><a href="https://www.linuxfromscratch.org/blfs/view/11.3-systemd/introduction/systemd-units.html">https://www.linuxfromscratch.org/blfs/view/11.3-systemd/introduction/systemd-units.html</a><br></div><div class="gmail_default" style="font-size:small">We need to do some more work on these unit files.</div><div class="gmail_default" style="font-size:small"><br></div><div>--<br></div><div dir="ltr" class="gmail_signature"><div dir="ltr"><span style="font-family:arial,sans-serif">Shedi</span></div></div></div>