diff --git a/Linux_reinstall/Ubuntu/CloudInit/ipv4_static_interfaces.cfg b/Linux_reinstall/Ubuntu/CloudInit/ipv4_static_interfaces.cfg index 7882941..30ddd70 100644 --- a/Linux_reinstall/Ubuntu/CloudInit/ipv4_static_interfaces.cfg +++ b/Linux_reinstall/Ubuntu/CloudInit/ipv4_static_interfaces.cfg @@ -64,19 +64,21 @@ network: # Enable sshd service. # Reload systemd. # Make sshd service loading automatically at the next reboot. -# Restart the sshd service. +# Kill the original sshd service so that to liberate the occupation of "0.0.0.0:22" and "[::]:22" to avoid "error: Bind to port sth on sth failed: Address already in use." causes restarting and applying new configs failure of the sshd service. +# Restart sshd service. # Disable kernel need to restart: https://askubuntu.com/questions/1349884/how-to-disable-pending-kernel-upgrade-message # Install some common components. # Configure vim for more convenient to use. # Rename netplan config file. -# Configure fail2ban. +# Configure and restart fail2ban. # Update grub. # Delete cloud-init config file itself and disable it permanently after first execution. runcmd: - - systemctl disable --now ssh.socket - - systemctl enable --now ssh.service + - systemctl disable ssh.socket + - systemctl enable ssh.service - systemctl daemon-reload - update-rc.d ssh enable + - kill -9 $(ps -ef | grep '/usr/sbin/sshd' | gawk '$0 !~/grep/ {print $2}' | tr -s '\n' ' ') - /etc/init.d/ssh restart - sed -i 's/#$nrconf{restart} = '"'"'i'"'"';/$nrconf{restart} = '"'"'a'"'"';/g' /etc/needrestart/needrestart.conf - sed -i "s/#\$nrconf{kernelhints} = -1;/\$nrconf{kernelhints} = -1;/g" /etc/needrestart/needrestart.conf