I researched this issue for about 6+ hours or so and finally came across
this thread. I have been able to solve the issue thanks to this thread.


# ENVIRONMENT INFO:
Ubuntu 20.04.2 LTS (Focal Fossa)
OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f  31 Mar 2020


# PROBLEM:
        Open /etc/ssh/sshd_config and add: "ListenAddress=192.168.5.123"
        The IP address specified is the local IP of the Ethernet adapter on the 
motherboard.

        # EXPECTED RESULT: Boot the server, and then be able to login to
the specified IP address via SSH from a remote workstation.

        # ACTUAL RESULT: Boot the server, and I am unable to login to
the specified IP address via SSH from a remote workstation.

        # NOTES: If I remove "ListenAddress=192.168.5.123" from
sshd_config, reboot the server, then I am able to login via SSH from a
remote workstation.

                If the server is already on, and I am logged in via SSH,
and I add "ListenAddress=192.168.5.123" to sshd_config, and then I run
"sudo systemctl restart sshd", and then I run "sudo systemctl status
sshd", I see that sshd is listening to the IP address specified with no
errors. I am then able to logout/login of the SSH session successfully.

                However, if I add "ListenAddress=192.168.5.123" to sshd_config, 
reboot the server, then I am unable to log into the server via SSH from a 
different workstation. When I check /var/log/auth.log I find this error:
                
                        Apr 29 08:09:45 user sshd[1395]: error: Bind to port 
12345 on 192.168.5.123 failed: Cannot assign requested address.
                        Apr 29 08:09:45 user sshd[1395]: fatal: Cannot bind any 
address.

                This leads me to believe that sshd is attempting to bind
to the Ethernet adapter's IP address BEFORE the Ethernet adapter
receives its IP address from the DHCP server (I think). Thus resulting
in this fatal error.


## SOLUTION:
        Open /etc/systemd/system/sshd.service and change:

                FROM:

                        [Unit]
                        After=network.target auditd.service

                TO:

                        [Unit]
                        After=network-online.target auditd.service
                        
        See this article for details: 
https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/#cutthecraphowdoimakesurethatmyservicestartsafterthenetworkisreallyonline
        
        With this configuration in place, I add "ListenAddress=192.168.5.123" 
to sshd_config, reboot the server, and then I am successfully able to login via 
SSH from a remote workstation.

-- 
You received this bug notification because you are a member of Ubuntu
Touch seeded packages, which is subscribed to openssh in Ubuntu.
https://bugs.launchpad.net/bugs/216847

Title:
  sshd will not start at boot if ListenAddress is set, because network
  interface is not yet up

Status in portable OpenSSH:
  Unknown
Status in openssh package in Ubuntu:
  Confirmed

Bug description:
  Binary package hint: openssh-server

  The sshd will not start at boot if the ListenAddress option in
  /etc/ssh/sshd_config is set to an IPv4 address other then 0.0.0.0 .

  I am using Ubuntu 7.10 and the version 1:4.6p1-5ubuntu0.2 of the 
openssh-server package.
  I would expect that sshd is started after boot but it will not and I found 
this in /var/log/auth.log:

  sshd[4527]: error: Bind to port 22 on 10.1.1.22 failed: Cannot assign 
requested address.
  sshd[4527]: fatal: Cannot bind any address.

  Once the System is started you can start/stop the sshd with the
  /etc/init.d/ssh script without any problems.

To manage notifications about this bug go to:
https://bugs.launchpad.net/openssh/+bug/216847/+subscriptions

-- 
Mailing list: https://launchpad.net/~touch-packages
Post to     : touch-packages@lists.launchpad.net
Unsubscribe : https://launchpad.net/~touch-packages
More help   : https://help.launchpad.net/ListHelp

Reply via email to