Bug 1222467

Summary: sshd displays error when binding to custom port
Product: [openSUSE] openSUSE Tumbleweed Reporter: Luca Billi <noreply.section+dev>
Component: BasesystemAssignee: E-mail List <screening-team-bugs>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: hpj, opensuse, pmonrealgonzalez, santiago.zarate
Version: CurrentFlags: santiago.zarate: needinfo? (hpj)
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Luca Billi 2024-04-08 12:37:41 UTC
Starting with tw 20240404, sshd.service logs the following error:

sshd[1566]: Server listening on 0.0.0.0 port 2222.
sshd[1566]: Server listening on :: port 2222.
sshd[1566]: error: Bind to port 2222 on 0.0.0.0 failed: Address already in use.
sshd[1566]: error: Bind to port 2222 on :: failed: Address already in use.

when a drop-in conf file is placed in /etc/ssh/sshd_config.d.

> cat /etc/ssh/sshd_config.d/myport.conf
Port 2222

Despite the error message, sshd seems to work as expected.

The error message is not present if no file is placed in /etc/ssh/sshd_config.d/ and it was not present before tw 20240404.
Comment 1 Santiago Zarate 2024-04-08 17:32:39 UTC
(In reply to Luca Billi from comment #0)
> Starting with tw 20240404, sshd.service logs the following error:
> 
> sshd[1566]: Server listening on 0.0.0.0 port 2222.
> sshd[1566]: Server listening on :: port 2222.
> sshd[1566]: error: Bind to port 2222 on 0.0.0.0 failed: Address already in
> use.
> sshd[1566]: error: Bind to port 2222 on :: failed: Address already in use.
> 
> when a drop-in conf file is placed in /etc/ssh/sshd_config.d.
> 
> > cat /etc/ssh/sshd_config.d/myport.conf
> Port 2222
> 
> Despite the error message, sshd seems to work as expected.
> 
> The error message is not present if no file is placed in
> /etc/ssh/sshd_config.d/ and it was not present before tw 20240404.

that's odd, but I can confirm that it happens on one of my tw systems with the latest updates (openssh 9.6p1)

Asking the bugowner
Comment 2 Arnav Singh 2024-04-10 05:23:23 UTC
I was about to file a different bug, but it has the same root cause as this one
so I will post here. The problem is that /usr/etc/ssh/sshd_config contains
two copies of the directive to include /etc/ssh/sshd_config.d/*.conf ,
so dropins get included twice.

    # To modify the system-wide sshd configuration, create a "*.conf" file under
    # "/etc/ssh/sshd_config.d/" which will be automatically included below.
    # Don't edit this configuration file itself if possible to avoid update
    # problems.
    Include /etc/ssh/sshd_config.d/*.conf

    # The strategy used for options in the default sshd_config shipped with
    # OpenSSH is to specify options with their default value where
    # possible, but leave them commented.  Uncommented options override the
    # default value.
    Include /usr/etc/ssh/sshd_config.d/*.conf

    # To modify the system-wide sshd configuration, create a  *.conf  file under
    #  /etc/ssh/sshd_config.d/  which will be automatically included below
    Include /etc/ssh/sshd_config.d/*.conf

It started happening now because the second copy is added by
the new openssh-9.6p1-crypto-policies.patch while the first copy was being
added by openssh-8.4p1-ssh_config_d.patch

My case was that my dropin contains `HostKey /etc/ssh/ssh_host_ed25519_key`
to force the use of only ED25519 key, but because the dropin gets included twice
the server also advertises the key twice, which leads to clients printing:

    client_input_hostkeys: received duplicated ssh-ed25519 host key
Comment 3 Arnav Singh 2024-04-11 06:43:12 UTC
https://build.opensuse.org/request/show/1166764
Comment 6 Luca Billi 2024-04-16 14:34:52 UTC
Fixed in tw 20240414