Fix issue with sshd_config for PasswordAuthentication, AddressFamily.

This commit is contained in:
Nick Hepler 2024-10-11 17:01:20 -04:00
parent 0d8c8d264b
commit 226d1e292c

View File

@ -100,10 +100,18 @@ if [ -f "$sshd_config" ]; then
sed -i 's/^PermitRootLogin .*/PermitRootLogin no/' "$sshd_config" || echo "PermitRootLogin no" >> "$sshd_config" sed -i 's/^PermitRootLogin .*/PermitRootLogin no/' "$sshd_config" || echo "PermitRootLogin no" >> "$sshd_config"
# Set PasswordAuthentication to no # Set PasswordAuthentication to no
sed -i 's/^PasswordAuthentication .*/PasswordAuthentication no/' "$sshd_config" || echo "PasswordAuthentication no" >> "$sshd_config" if grep -q '^#PasswordAuthentication' "$sshd_config"; then
sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication no/' "$sshd_config"
else
sed -i 's/^PasswordAuthentication .*/PasswordAuthentication no/' "$sshd_config" || echo "PasswordAuthentication no" >> "$sshd_config"
fi
# Ensure AddressFamily inet is not commented out # Ensure AddressFamily inet is set
sed -i 's/^#\?\(AddressFamily inet\)/\1/' "$sshd_config" if grep -q '^#AddressFamily' "$sshd_config"; then
sed -i 's/^#AddressFamily.*/AddressFamily inet/' "$sshd_config"
else
sed -i 's/^AddressFamily .*/AddressFamily inet/' "$sshd_config" || echo "AddressFamily inet" >> "$sshd_config"
fi
else else
echo "sshd_config file not found. Exiting." echo "sshd_config file not found. Exiting."
exit 1 exit 1