7

I'm running Arch Linux. After I reboot, the sshd.service fails to start due to the network not yet being up. I have to manually run:

sudo systemctl restart sshd

Once I do that, the sshd service starts without any errors and it operates correctly. How do I resolve this so that the systemd sshd.service will start automatically as it should?

Here are the logs:

May 06 15:47:23 server2 nm-dispatcher[471]: req:3 'connectivity-change': completed: no scripts
May 06 15:47:23 server2 nm-dispatcher[471]: req:3 'connectivity-change': new request (0 scripts)
May 06 15:47:23 server2 NetworkManager[440]: <info>  [1525636043.9284] manager: NetworkManager state is now CONNECTED_GLOBAL

May 06 15:47:22 server2 nm-dispatcher[471]: req:2 'up' [eth0]: completed: no scripts
May 06 15:47:22 server2 nm-dispatcher[471]: req:2 'up' [eth0]: new request (0 scripts)
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6632] manager: startup complete
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6626] device (eth0): Activation: successful, device activated.
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6566] policy: set 'Wired connection 1' (eth0) as default for IPv4 routing and DNS
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6565] manager: NetworkManager state is now CONNECTED_SITE
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6558] manager: NetworkManager state is now CONNECTED_LOCAL
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6557] device (eth0): state change: secondaries -> activated (reason 'none', sys-iface-state: 'manag>
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6555] device (eth0): state change: ip-check -> secondaries (reason 'none', sys-iface-state: 'manage>
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6549] device (eth0): state change: ip-config -> ip-check (reason 'none', sys-iface-state: 'managed')
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6541] dhcp4 (eth0): state changed unknown -> bound
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6536] dhcp4 (eth0):   gateway 10.10.0.1
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6536] dhcp4 (eth0):   hostname 'server2'
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6536] dhcp4 (eth0):   domain name 'oaks'
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6536] dhcp4 (eth0):   nameserver '10.10.0.1'
May 06 15:47:22 server2 dbus-daemon[439]: [system] Activation via systemd failed for unit 'dbus-org.freedesktop.Avahi.service': Unit dbus-org.freedesktop.Avahi.serv>
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6535] dhcp4 (eth0):   expires in 648000 seconds
May 06 15:47:22 server2 dbus-daemon[439]: [system] Activating via systemd: service name='org.freedesktop.Avahi' unit='dbus-org.freedesktop.Avahi.service' requested >
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6535] dhcp4 (eth0):   plen 24
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6535] dhcp4 (eth0):   address 10.10.1.12
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6293] dhcp4 (eth0): activation: beginning transaction (timeout in 45 seconds)
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6284] device (eth0): state change: config -> ip-config (reason 'none', sys-iface-state: 'managed')
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6275] device (eth0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6262] manager: NetworkManager state is now CONNECTING
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6258] device (eth0): state change: disconnected -> prepare (reason 'none', sys-iface-state: 'manage>
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6251] device (eth0): Activation: starting connection 'Wired connection 1' (5b9f0bf9-ed10-31e5-bcad->
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6224] policy: auto-activating connection 'Wired connection 1'
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6206] device (eth0): state change: unavailable -> disconnected (reason 'carrier-changed', sys-iface>
May 06 15:47:22 server2 NetworkManager[440]: <info>  [1525636042.6196] device (eth0): carrier: link connected
May 06 15:47:22 server2 kernel: IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
May 06 15:47:22 server2 kernel: e1000e: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: Rx/Tx
May 06 15:47:22 server2 udisksd[598]: udisks daemon version 2.7.6 starting
May 06 15:47:22 server2 systemd[1]: Starting Disk Manager...

May 06 15:47:20 server2 systemd[1]: sshd.service: Failed with result 'exit-code'.
May 06 15:47:20 server2 systemd[1]: sshd.service: Main process exited, code=exited, status=255/n/a
May 06 15:47:20 server2 sshd[564]: fatal: Cannot bind any address.
May 06 15:47:20 server2 sshd[564]: error: Bind to port 22 on 10.10.1.12 failed: Cannot assign requested address.
May 06 15:47:20 server2 systemd[1]: Started OpenSSH Daemon.
May 06 15:47:20 server2 systemd[1]: Stopped OpenSSH Daemon.
May 06 15:47:20 server2 systemd[1]: sshd.service: Scheduled restart job, restart counter is at 3.
May 06 15:47:20 server2 systemd[1]: sshd.service: Service hold-off time over, scheduling restart.
May 06 15:47:19 server2 systemd[1]: Startup finished in 12.430s (firmware) + 6.006s (loader) + 8.847s (kernel) + 2.106s (userspace) = 29.391s.
May 06 15:47:19 server2 polkitd[543]: Acquired the name org.freedesktop.PolicyKit1 on the system bus
May 06 15:47:19 server2 systemd[1]: Started Authorization Manager.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Successfully activated service 'org.freedesktop.PolicyKit1'
May 06 15:47:19 server2 polkitd[543]: Finished loading, compiling and executing 2 rules
May 06 15:47:19 server2 polkitd[543]: Error compiling script /etc/polkit-1/rules.d/40-allow-passwordless-printer-admin.rules
May 06 15:47:19 server2 polkitd[543]: Loading rules from directory /usr/share/polkit-1/rules.d
May 06 15:47:19 server2 polkitd[543]: Loading rules from directory /etc/polkit-1/rules.d
May 06 15:47:19 server2 polkitd[543]: Started polkitd version 0.114
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.9110] supplicant: wpa_supplicant running
May 06 15:47:19 server2 wpa_supplicant[546]: Successfully initialized wpa_supplicant
May 06 15:47:19 server2 systemd[1]: Started WPA supplicant.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Successfully activated service 'fi.w1.wpa_supplicant1'
May 06 15:47:19 server2 systemd[1]: Started CUPS Scheduler.
May 06 15:47:19 server2 colord[526]: failed to get session [pid 465]: No data available
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.8565] device (wlan0): set-hw-addr: set MAC address to 02:6B:94:A4:D1:08 (scanning)
May 06 15:47:19 server2 kernel: IPv6: ADDRCONF(NETDEV_UP): wlan0: link is not ready
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.8563] device (wlan0): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'e>
May 06 15:47:19 server2 systemd[1]: sshd.service: Failed with result 'exit-code'.
May 06 15:47:19 server2 sshd[540]: fatal: Cannot bind any address.
May 06 15:47:19 server2 systemd[1]: sshd.service: Main process exited, code=exited, status=255/n/a
May 06 15:47:19 server2 sshd[540]: error: Bind to port 22 on 10.10.1.12 failed: Cannot assign requested address.
May 06 15:47:19 server2 systemd[1]: Starting WPA supplicant...
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.8527] manager: (wlan0): new 802.11 WiFi device (/org/freedesktop/NetworkManager/Devices/3)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.8521] device (wlan0): driver supports Access Point (AP) mode
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.8519] wifi-nl80211: (wlan0): using nl80211 for WiFi device control
May 06 15:47:19 server2 dbus-daemon[439]: [system] Activating via systemd: service name='fi.w1.wpa_supplicant1' unit='wpa_supplicant.service' requested by ':1.1' (u>
May 06 15:47:19 server2 systemd[1]: Starting Authorization Manager...
May 06 15:47:19 server2 systemd[1]: Started OpenSSH Daemon.
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.8493] manager: rfkill: WiFi now disabled by radio killswitch
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.8492] rfkill1: found WiFi radio killswitch (at /sys/devices/pci0000:00/0000:00:1d.1/0000:05:00.0/ie>
May 06 15:47:19 server2 systemd[1]: Stopped OpenSSH Daemon.
May 06 15:47:19 server2 systemd[1]: sshd.service: Scheduled restart job, restart counter is at 2.
May 06 15:47:19 server2 systemd[1]: sshd.service: Service hold-off time over, scheduling restart.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Activating via systemd: service name='org.freedesktop.PolicyKit1' unit='polkit.service' requested by ':1.1' (uid=>
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.8479] ovsdb: Could not connect: No such file or directory
May 06 15:47:19 server2 kernel: IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready

May 06 15:47:19 server2 systemd[1]: sshd.service: Failed with result 'exit-code'.
May 06 15:47:19 server2 systemd[1]: sshd.service: Main process exited, code=exited, status=255/n/a
May 06 15:47:19 server2 sshd[525]: fatal: Cannot bind any address.
May 06 15:47:19 server2 sshd[525]: error: Bind to port 22 on 10.10.1.12 failed: Cannot assign requested address.
May 06 15:47:19 server2 systemd[1]: Starting Manage, Install and Generate Color Profiles...
May 06 15:47:19 server2 systemd[1]: Started OpenSSH Daemon.
May 06 15:47:19 server2 systemd[1]: Stopped OpenSSH Daemon.
May 06 15:47:19 server2 systemd[1]: sshd.service: Scheduled restart job, restart counter is at 1.
May 06 15:47:19 server2 systemd[1]: sshd.service: Service hold-off time over, scheduling restart.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Activating via systemd: service name='org.freedesktop.ColorManager' unit='colord.service' requested by ':1.9' (ui>
May 06 15:47:19 server2 kernel: ath: Regpair used: 0x69
May 06 15:47:19 server2 kernel: ath: Country alpha2 being used: 00
May 06 15:47:19 server2 kernel: ath: EEPROM indicates we should expect a direct regpair map
May 06 15:47:19 server2 kernel: ath: EEPROM regdomain: 0x69
May 06 15:47:19 server2 kernel: IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready

May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.6322] device (eth0): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'ex>
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.6298] settings: (eth0): created default wired connection 'Wired connection 1'
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.6283] keyfile: add connection in-memory (5b9f0bf9-ed10-31e5-bcad-42dadabdcdad,"Wired connection 1")
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.6253] manager: (eth0): new Ethernet device (/org/freedesktop/NetworkManager/Devices/2)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.6223] manager: (lo): new Generic device (/org/freedesktop/NetworkManager/Devices/1)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.6207] device (lo): carrier: link connected
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.6185] Loaded device plugin: NMOvsFactory (/usr/lib/NetworkManager/libnm-device-plugin-ovs.so)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.6170] Loaded device plugin: NMTeamFactory (/usr/lib/NetworkManager/libnm-device-plugin-team.so)
May 06 15:47:19 server2 kernel: ath10k_pci 0000:05:00.0: htt-ver 3.47 wmi-op 4 htt-op 3 cal otp max-sta 32 raw 0 hwcrypto 1
May 06 15:47:19 server2 kernel: ath10k_pci 0000:05:00.0: Unknown eventid: 90118
May 06 15:47:19 server2 kernel: ath10k_pci 0000:05:00.0: Unknown eventid: 118809
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5679] Loaded device plugin: NMWifiFactory (/usr/lib/NetworkManager/libnm-device-plugin-wifi.so)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5647] Loaded device plugin: NMBluezManager (/usr/lib/NetworkManager/libnm-device-plugin-bluetooth.s>
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5550] Loaded device plugin: NMWwanFactory (/usr/lib/NetworkManager/libnm-device-plugin-wwan.so)

May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5299] Loaded device plugin: NMAtmManager (/usr/lib/NetworkManager/libnm-device-plugin-adsl.so)

May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5276] Loaded device plugin: NMVxlanDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5276] Loaded device plugin: NMVlanDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5276] Loaded device plugin: NMVethDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5276] Loaded device plugin: NMTunDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5276] Loaded device plugin: NMPppDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5276] Loaded device plugin: NMMacvlanDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5275] Loaded device plugin: NMMacsecDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5275] Loaded device plugin: NMIPTunnelDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5275] Loaded device plugin: NMInfinibandDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5275] Loaded device plugin: NMEthernetDeviceFactory (internal)
May 06 15:47:19 server2 nm-dispatcher[471]: req:1 'hostname': completed: no scripts
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5275] Loaded device plugin: NMDummyDeviceFactory (internal)
May 06 15:47:19 server2 nm-dispatcher[471]: req:1 'hostname': new request (0 scripts)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5275] Loaded device plugin: NMBridgeDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5275] Loaded device plugin: NMBondDeviceFactory (internal)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5275] dhcp-init: Using DHCP client 'internal'
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5274] manager: Networking is enabled by state file
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5274] manager: rfkill: WWAN enabled by radio killswitch; enabled by state file
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5273] manager: rfkill: WiFi enabled by radio killswitch; disabled by state file

May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.5267] settings: loaded plugin iBFT: (c) 2014 Red Hat, Inc.  To report bugs please use the NetworkMa>

May 06 15:47:19 server2 ntpd[458]: Command line: /usr/bin/ntpd -g -u ntp:ntp
May 06 15:47:19 server2 ntpd[458]: ntpd [email protected] Wed Mar  7 18:48:03 UTC 2018 (1): Starting


May 06 15:47:19 server2 systemd[1]: Started Network Manager Script Dispatcher Service.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Successfully activated service 'org.freedesktop.nm_dispatcher'

May 06 15:47:19 server2 systemd[1]: sshd.service: Failed with result 'exit-code'.
May 06 15:47:19 server2 systemd[1]: sshd.service: Main process exited, code=exited, status=255/n/a
May 06 15:47:19 server2 sshd[463]: fatal: Cannot bind any address.
May 06 15:47:19 server2 sshd[463]: error: Bind to port 22 on 10.10.1.12 failed: Cannot assign requested address.
May 06 15:47:19 server2 systemd[1]: Started Simple Desktop Display Manager.
May 06 15:47:19 server2 autossh[462]: ssh child pid is 476
May 06 15:47:19 server2 systemd[1]: Started Permit User Sessions.
May 06 15:47:19 server2 autossh[462]: starting ssh (count 1)
May 06 15:47:19 server2 autossh[462]: port set to 0, monitoring disabled
May 06 15:47:19 server2 autossh[468]: ssh child pid is 475
May 06 15:47:19 server2 autossh[468]: starting ssh (count 1)
May 06 15:47:19 server2 autossh[461]: ssh child pid is 474
May 06 15:47:19 server2 autossh[459]: ssh child pid is 473
May 06 15:47:19 server2 autossh[461]: starting ssh (count 1)
May 06 15:47:19 server2 autossh[460]: ssh child pid is 472
May 06 15:47:19 server2 autossh[459]: starting ssh (count 1)
May 06 15:47:19 server2 autossh[460]: starting ssh (count 1)
May 06 15:47:19 server2 systemd[1]: Starting Network Manager Script Dispatcher Service...
May 06 15:47:19 server2 autossh[466]: ssh child pid is 470
May 06 15:47:19 server2 autossh[466]: starting ssh (count 1)
May 06 15:47:19 server2 autossh[468]: port set to 0, monitoring disabled
May 06 15:47:19 server2 autossh[461]: port set to 0, monitoring disabled
May 06 15:47:19 server2 autossh[459]: port set to 0, monitoring disabled
May 06 15:47:19 server2 autossh[460]: port set to 0, monitoring disabled
May 06 15:47:19 server2 autossh[466]: port set to 0, monitoring disabled
May 06 15:47:19 server2 systemd[1]: Starting Permit User Sessions...
May 06 15:47:19 server2 systemd[1]: Starting CUPS Scheduler...
May 06 15:47:19 server2 systemd[1]: Started OpenSSH Daemon.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Activating via systemd: service name='org.freedesktop.nm_dispatcher' unit='dbus-org.freedesktop.nm-dispatcher.ser>
May 06 15:47:19 server2 systemd[1]: Starting Network Time Service...
May 06 15:47:19 server2 systemd[1]: Reached target Network.
May 06 15:47:19 server2 systemd[1]: Started Network Manager.
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.4679] manager[0x5631afba8080]: rfkill: WWAN hardware radio set enabled
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.4678] manager[0x5631afba8080]: rfkill: WiFi hardware radio set disabled
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.4674] dns-mgr[0x5631afbc3130]: init: dns=default, rc-manager=symlink
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.4672] hostname: hostname changed from (none) to "server2"
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.4672] hostname: hostname: using hostnamed
May 06 15:47:19 server2 systemd[1]: Started Hostname Service.
May 06 15:47:19 server2 dbus-daemon[439]: [system] Successfully activated service 'org.freedesktop.hostname1'
May 06 15:47:19 server2 kernel: input: HDA NVidia HDMI/DP,pcm=9 as /devices/pci0000:00/0000:00:01.0/0000:01:00.1/sound/card1/input19
May 06 15:47:19 server2 kernel: input: HDA NVidia HDMI/DP,pcm=8 as /devices/pci0000:00/0000:00:01.0/0000:01:00.1/sound/card1/input18
May 06 15:47:19 server2 kernel: input: HDA NVidia HDMI/DP,pcm=7 as /devices/pci0000:00/0000:00:01.0/0000:01:00.1/sound/card1/input17
May 06 15:47:19 server2 kernel: input: HDA NVidia HDMI/DP,pcm=3 as /devices/pci0000:00/0000:00:01.0/0000:01:00.1/sound/card1/input16
May 06 15:47:19 server2 systemd[1]: Starting Hostname Service...
May 06 15:47:19 server2 dbus-daemon[439]: [system] Activating via systemd: service name='org.freedesktop.hostname1' unit='dbus-org.freedesktop.hostname1.service' re>
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.1725] manager[0x5631afba8080]: monitoring kernel firmware directory '/usr/lib/firmware'.
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.1684] Read config: /etc/NetworkManager/NetworkManager.conf (lib: 20-connectivity.conf)
May 06 15:47:19 server2 NetworkManager[440]: <info>  [1525636039.1683] NetworkManager (version 1.10.6-3, Arch Linux) is starting... (for the first time)
May 06 15:47:19 server2 systemd-logind[441]: Watching system buttons on /dev/input/event4 (  USB Keyboard)
May 06 15:47:19 server2 systemd-logind[441]: Watching system buttons on /dev/input/event3 (  USB Keyboard)
May 06 15:47:19 server2 systemd-logind[441]: Watching system buttons on /dev/input/event0 (Sleep Button)
May 06 15:47:19 server2 systemd-logind[441]: Watching system buttons on /dev/input/event1 (Power Button)
May 06 15:47:19 server2 systemd-logind[441]: Watching system buttons on /dev/input/event2 (Power Button)
May 06 15:47:19 server2 systemd-logind[441]: New seat seat0.
May 06 15:47:19 server2 systemd[1]: Reached target Timers.
May 06 15:47:19 server2 systemd[1]: Started Daily man-db cache update.
May 06 15:47:19 server2 systemd[1]: Started Daily verification of password and group files.
May 06 15:47:19 server2 systemd[1]: Started Daily Cleanup of Snapper Snapshots.
May 06 15:47:19 server2 systemd[1]: Started Daily autocommit of changes in /etc directory.
May 06 15:47:19 server2 systemd[1]: Starting Login Service...
May 06 15:47:19 server2 systemd[1]: Starting Network Manager...
May 06 15:47:19 server2 systemd[1]: Started D-Bus System Message Bus.
May 06 15:47:19 server2 systemd[1]: Reached target Basic System.
May 06 15:47:19 server2 systemd[1]: Reached target Sockets.
May 06 15:47:19 server2 systemd[1]: Listening on CUPS Scheduler.
May 06 15:47:19 server2 systemd[1]: Listening on D-Bus System Message Bus Socket.
May 06 15:47:19 server2 systemd[1]: Started Daily Cleanup of Temporary Directories.
May 06 15:47:19 server2 systemd[1]: Started Timeline of Snapper Snapshots.
May 06 15:47:19 server2 systemd[1]: Reached target Paths.
May 06 15:47:19 server2 systemd[1]: Started CUPS Scheduler.
May 06 15:47:19 server2 systemd[1]: Started Daily rotation of log files.
May 06 15:47:19 server2 systemd[1]: Reached target System Initialization.
May 06 15:47:19 server2 systemd[1]: Started Update UTMP about System Boot/Shutdown.
May 06 15:47:19 server2 systemd[1]: Starting Update UTMP about System Boot/Shutdown...
May 06 15:47:19 server2 systemd[1]: Started Create Volatile Files and Directories.
May 06 15:47:19 server2 systemd[1]: Starting Create Volatile Files and Directories...
May 06 15:47:19 server2 systemd[1]: Started Flush Journal to Persistent Storage.
May 06 15:47:18 server2 systemd[1]: Reached target Sound Card.

/usr/lib/systemd/system/sshd.service:

[Unit]
Description=OpenSSH Daemon
Wants=sshdgenkeys.service
After=sshdgenkeys.service
After=network.target

[Service]
ExecStart=/usr/bin/sshd -D
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=always

[Install]
WantedBy=multi-user.target

# This service file runs an SSH daemon that forks for each incoming connection.
# If you prefer to spawn on-demand daemons, use sshd.socket and [email protected].

/etc/NetworkManager/NetworkManager.conf is empty and /etc/NetworkManager/conf.d/ is empty.

Noteable log entries:

  • May 06 15:47:22 server2 kernel: e1000e: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: Rx/Tx
  • May 06 15:47:19 server2 systemd[1]: sshd.service: Failed with result 'exit-code'.
  • May 06 15:47:19 server2 systemd[1]: Reached target Network.

It appears that the system is reaching target Network before the actual interface is up. How is this resolved?

1
  • 2
    May 06 15:47:19 server2 sshd[540]: error: Bind to port 22 on 10.10.1.12 failed: Cannot assign requested address. probably means ListenAddress was changed from the default. If sshd didn't try to bind to a specific address it wouldn't have any trouble. There's still firewall or host.allow if needed
    – A.B
    Commented May 6, 2018 at 22:24

5 Answers 5

13

As A.B indicated, your ssh config has likely been adjusted to listen on a specific IP address. If that IP address is not available when sshd starts, then the service will fail.
By default, sshd is configured to liste on 0.0.0.0, which means any address, and thus doesn't depend on a specific IP being available.

There are 2 ways you can address this:

Start after network-online.target

systemd provides a network-online.target unit for services which need the network to be fully up (all interfaces configured). Thus you can make sshd start after this unit to start up after the interface is configured

mkdir /etc/systemd/system/sshd.service.d

cat > /etc/systemd/system/sshd.service.d/network-online.conf <<EOF
[Unit]
After=network-online.target
EOF

systemctl daemon-reload

Allow binding to non-local addresses

The other option is to allow listening on addresses which are not present on the host.
This solution is system wide, so will apply to any service, not just sshd.

echo 'net.ipv4.ip_nonlocal_bind = 1' > /etc/sysctl.d/99-nonlocal_bind.conf

systemctl restart systemd-sysctl.service
4
  • I'll try replacing After=network.target with After=network-online.target. It strikes me that this should be the default behavior anyway. The listen address was changed to tighten security, and I prefer to leave as is. I have other computers that work fine with a specific listen address specified. This computer must have more delay than the others in obtaining an address via DHCP.
    – MountainX
    Commented May 7, 2018 at 1:26
  • Instead of manually creating the drop-in directory and file for sshd.service, you can also use systemd edit sshd.service (prepending sudo as required.) The main difference is that the resulting file is always called override.conf, and the unit is automatically reloaded if you commit the changes.
    – ErikF
    Commented May 7, 2018 at 4:41
  • Did this work for anyone? I have tried this and logs show that network-online does finish before ssh tries to start, but ssh still fails because it cannot bind. Commented Feb 10, 2019 at 6:43
  • Thanks! Although I set it to start after NetworkManager-wait-online.service instead (Centos 8) and this worked for me. Nothing else – including making it require NetworkManager-wait-online.service – would work for me.
    – miken32
    Commented Dec 14, 2019 at 3:06
5

Building on @phemmer answer, I got the same problem and I fixed it by adding

 [Unit]
 Wants=network-online.target
 After=network-online.target

in the /etc/systemd/system/sshd.service.d configuration file.

Also make sure that the right wait service for your network manager is enabled, as detailed here. For example:

 $ systemctl is-enabled NetworkManager-wait-online.service systemd-networkd-wait-online.service
2
  • This should be the accepted answer, because the accepted answer solution doesn't work.
    – Binar Web
    Commented Mar 9, 2021 at 11:39
  • Additional info I used while implementing this answer. To add the Unit/Wants/After, use sudo systemctl edit sshd.service which will create an override.conf file in /etc/systemd/system/ssh.service.d To know which is the right wait service for your system, first see which underlying service is running systemctl NetworkManager status and systemctl status systemd-networkd and then check this is-enabled output to make sure the right one is enabled.
    – MikeV
    Commented Jan 11 at 0:17
1

None of the above worked for me. I resolved the issue using a cronjob.

sudo crontab -e

Then add:

@reboot sleep 10; systemctl start sshd
0

I've had the same problem and stumbled upon this question couple times while searching on the net.

The workaround consists of binding sshd on two addresses. The address of the desired interface, like 192.168.0.23 and the address of the loopback 127.0.0.1.

ListenAddress 127.0.0.1
ListenAddress 192.168.0.23

This doesn't prevent ssh from raising an error though. But instead of crashing, ssh restarts after a second and then binds to the correct address. Here is an example of the difference.

  • With 192.168.0.23 only
sshd[378]: error: Bind to port 22 on 192.168.0.23 failed: Cannot assign requested address.
sshd[378]: fatal: Cannot bind any address.
systemd[1]: ssh.service: Main process exited, code=exited, status=255/n/a
systemd[1]: ssh.service: Unit entered failed state.
  • With 192.168.0.23 and 127.0.0.1
sshd[390]: error: Bind to port 22 on 192.168.0.23 failed: Cannot assign requested address.
sshd[390]: Server listening on 127.0.0.1 port 22.
sshd[390]: Received SIGHUP; restarting.
sshd[390]: Server listening on 192.168.0.23 port 22.
sshd[390]: Server listening on 127.0.0.1 port 22.
1
  • 1
    For me, this didn't have the intended effect. Yes, sshd starts up, but is only reachable through 127.0.0.1, not from the local network. And it also doesn't seem to correct that after the network is up. Commented May 21, 2023 at 0:04
0

If you are using NetworkManager, try:

systemctl enable NetworkManager-wait-online.service

In my case, overrides where not the answer. The key is the definition of network.target and network-online.target. My expectation was that the network is connected then; but it rather means that the process of connecting was reached. In other words, it may be still connecting, and there is no working internet connection yet.

The only working solution that I found was to switch from dhcpcd.service to NetworkManger. First, you will have the same problem, but now you can enable NetworkManager-wait-online.service. It "fixes" network.target by waiting until the internet connection is available.

But note that there is a reason why that service is not enabled by default. As a side-effect, it may slowdown the boot if it takes long to setup the network connection. In my own use case, the machine is connected by a LAN cable and the delay in startup is negligible. But be aware of that side-effect.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .