diff --git a/scripts/ssh.sh b/scripts/ssh.sh index 26571af..f9af7f0 100644 --- a/scripts/ssh.sh +++ b/scripts/ssh.sh @@ -99,13 +99,28 @@ if [ -f "/etc/selinux/config" ]; then sed -i.bak '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config fi setenforce 0; -sed -i "s/^#\?Port.*/Port $sshport/g" /etc/ssh/sshd_config; -sed -i "s/^#\?PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config; -sed -i "s/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config; -sed -i 's/#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config -sed -i 's/#ListenAddress ::/ListenAddress ::/' /etc/ssh/sshd_config -sed -i 's/#AddressFamily any/AddressFamily any/' /etc/ssh/sshd_config -sed -i '/^#UsePAM\|UsePAM/c #UsePAM no' /etc/ssh/sshd_config +if [ -f /etc/ssh/sshd_config ]; then + sed -i "s/^#\?Port.*/Port $sshport/g" /etc/ssh/sshd_config + sed -i "s/^#\?PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config + sed -i "s/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config + sed -i 's/#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config + sed -i 's/#ListenAddress ::/ListenAddress ::/' /etc/ssh/sshd_config + sed -i 's/#AddressFamily any/AddressFamily any/' /etc/ssh/sshd_config + sed -i '/^#UsePAM\|UsePAM/c #UsePAM no' /etc/ssh/sshd_config + sed -i "s/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g" /etc/ssh/sshd_config + sed -i '/^AuthorizedKeysFile/s/^/#/' /etc/ssh/sshd_config +fi +if [ -f /etc/ssh/sshd_config.d/50-cloud-init.conf ]; then + sed -i "s/^#\?Port.*/Port $sshport/g" /etc/ssh/sshd_config.d/50-cloud-init.conf + sed -i "s/^#\?PermitRootLogin.*/PermitRootLogin yes/g" /etc/ssh/sshd_config.d/50-cloud-init.conf + sed -i "s/^#\?PasswordAuthentication.*/PasswordAuthentication yes/g" /etc/ssh/sshd_config.d/50-cloud-init.conf + sed -i 's/#ListenAddress 0.0.0.0/ListenAddress 0.0.0.0/' /etc/ssh/sshd_config.d/50-cloud-init.conf + sed -i 's/#ListenAddress ::/ListenAddress ::/' /etc/ssh/sshd_config.d/50-cloud-init.conf + sed -i 's/#AddressFamily any/AddressFamily any/' /etc/ssh/sshd_config.d/50-cloud-init.conf + sed -i '/^#UsePAM\|UsePAM/c #UsePAM no' /etc/ssh/sshd_config.d/50-cloud-init.conf + sed -i "s/^#\?PubkeyAuthentication.*/PubkeyAuthentication no/g" /etc/ssh/sshd_config.d/50-cloud-init.conf + sed -i '/^AuthorizedKeysFile/s/^/#/' /etc/ssh/sshd_config.d/50-cloud-init.conf +fi remove_duplicate_lines "/etc/ssh/sshd_config" service ssh restart service sshd restart