Score:0

Why can't OpenSSH bind to any address when booting?

in flag

I'm working on an embedded linux board and I noticed the following on boot:

[FAILED] Failed to start OpenBSD Secure Shell server.

Then I ran sudo systemctl status sshd and got this:

[sudo] password for debian: 
ssh.service - OpenBSD Secure Shell server
  Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
  Active: failed (Result: exit-code) since Mon 2022-05-23 19:43:25 UTC; 33s ago
    Docs: man:sshd(8)
          man:sshd_config(5)
 Process: 639 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
 Process: 684 ExecStart=/usr/sbin/sshd -D $SSHD_OPTS (code=exited, status=255/E
Main PID: 684 (code=exited, status=255/EXCEPTION)

May 23 19:43:23 iot-server systemd[1]: Starting OpenBSD Secure Shell server...
May 23 19:43:24 iot-server sshd[684]: error: Bind to port 22 on 192.168.1.120 fa
May 23 19:43:24 iot-server sshd[684]: fatal: Cannot bind any address.
May 23 19:43:25 iot-server systemd[1]: ssh.service: Main process exited, code=ex
May 23 19:43:25 iot-server systemd[1]: ssh.service: Failed with result 'exit-cod
May 23 19:43:25 iot-server systemd[1]: Failed to start OpenBSD Secure Shell serv

All help I've found assumes that the address that can be bound is already in use. But for me this doesn't work from the start. The interesting thing is that if I run sudo systemctl start sshd then it starts to work and I get:

ssh.service - OpenBSD Secure Shell server
  Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab
  Active: active (running) since Mon 2022-05-23 19:53:01 UTC; 4s ago
    Docs: man:sshd(8)
          man:sshd_config(5)
 Process: 1471 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 1472 (sshd)
  Tasks: 1 (limit: 1026)
 Memory: 700.0K
 CGroup: /system.slice/ssh.service
         |_ 1472 /usr/sbin/sshd -D

May 23 19:53:01 iot-server systemd[1]: Starting OpenBSD Secure Shell server...
May 23 19:53:01 iot-server sshd[1472]: Server listening on 192.168.1.120 port 22
May 23 19:53:01 iot-server systemd[1]: Started OpenBSD Secure Shell server.

Why is it not binding on boot? The fact that I can make it work just fine without changes indicates that there is no problem, so I don't know what's missing.

us flag
Rob
It looks like the error output is truncated, maybe use the `-l` option to show in full. - My guess: The error `error: Bind to port 22 on 192.168.1.120` suggest that maybe your sshd configuration uses that specific IP address as the ListenAddress rather than the default (leaving the ListenAddress unset is the default) - and that IP address may not be configured and available yet when sshd is started.
m4l490n avatar
in flag
@Rob I don't think that's it. I have another Debian server where I have `ListenAddress 192.168.1.110` and it works just fine. I replicated the config from the server that works to my embedded server and updated the IP to `ListenAddress 192.168.1.120` as this is its address.
mikem avatar
cn flag
Is something else listening on port 22? What does "netstat -tulpn | grep 22" show you? Does the server have the address you think it does? What does "ifconfig -a" or "ip addr show" return?
m4l490n avatar
in flag
@mikem no, nothing is listening on port 22 and yes, I'm sure the address is that since I've verified with `ip addr show`. Also, I've reserved that address in my router to make sure it is always the same for this board. As I mentioned, nothing seems wrong because altough it doesn't work on boot, when board has booted I just do a `sudo systemctl start sshd` and it starts working perfectly fine.
mikem avatar
cn flag
Perhaps on bootup sshd is trying to start before the network is ready. is the address given by dhcp or is it static? Can you set systemd to delay the sshd startup, or make it dependent on network readiness? For testing, does anything change if you take out the ListenAddress setting, or if you change the port number?
Score:0
id flag

Same Error after a fresh install of Debian 11.

Resolve it by adding ‘auto enp7s0’ to my /etc/network/interfaces

Of course change ‘enp7s0’ by your interface network name.

‘auto’ specify interface that you want to launch on boot.

Seems that Debian 11 install do not add this to the configuration when you choose manual network configuration during installation. Probably what you have choose like me.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.