I turn on firewall with ufw with "systemctl enable ufw; systemctl start ufw" and "ufw enable". Then I set it with "ufw default deny incoming" to stop the incoming traffic. In the meanwhile, I allow ssh connection. So far, everything is all right. I am sure I can log in the server via ssh. But after I reboot, I can't log in via ssh anymore. I check ufw out as below
#ufw status
Status: active
To Action From
-- ------ ----
192.168.0.120 22/tcp ALLOW Anywhere
# systemctl status ufw
● ufw.service - Uncomplicated firewall
Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor
preset: enabled)
Active: active (exited) since Fri 2019-07-12 17:43:24 CST; 2min 36s ago
Docs: man:ufw(8)
Process: 241 ExecStart=/lib/ufw/ufw-init start quiet (code=exited,
status=0/SUCCESS)
Main PID: 241 (code=exited, status=0/SUCCESS)
Tasks: 0 (limit: 4915)
CGroup: /system.slice/ufw.service
ufw is enabled for sure.
After that, I allow ssh connection again just like I did first time.
Then I can log in vis ssh again.
I don't think it's normal.
But I don't know how to fix it?
[Update]
#systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor
preset: enabled)
Active: failed (Result: exit-code) since Mon 2019-07-15 11:53:22
CST; 2min 19s ago
Process: 603 ExecStart=/usr/sbin/sshd -D $SSHD_OPTS (code=exited, status=255)
Process: 537 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
Main PID: 603 (code=exited, status=255)
Jul 15 11:53:22 debian systemd[1]: Starting OpenBSD Secure Shell server...
Jul 15 11:53:22 debian systemd[1]: ssh.service: Main process exited,
code=exited, status=255/n/a
Jul 15 11:53:22 debian systemd[1]: Failed to start OpenBSD Secure Shell server.
Jul 15 11:53:22 debian systemd[1]: ssh.service: Unit entered failed state.
Jul 15 11:53:22 debian systemd[1]: ssh.service: Failed with result 'exit-code'
#/etc/ssh/sshd_config:
Port 22
ListenAddress 192.168.0.120
KbdInteractiveAuthentication no
ChallengeResponseAuthentication no
PermitRootLogin yes
AllowTcpForwarding no
AllowStreamLocalForwarding no
GatewayPorts no
PermitTunnel no
AllowUsers arcstor root
Compression yes
PubkeyAuthentication no
PasswordAuthentication yes
debian sshd[577]: error: Bind to port 22 on 192.168.0.120 failed: Cannot assign requested address. debian sshd[577]: fatal: Cannot bind any address.
I guessed sshd failed to get the IP while it is starting. Therefore, I add[Unit] Wants=network-online.target After=network.target network-online.target
on /etc/systemd/system/sshd.service. But in the end, it doesn't do the trick. – codexplorer Jul 16 '19 at 9:00