Created
December 4, 2022 19:25
-
-
Save AdamQuixote/573b29a3429602713a825c2fdd5beb91 to your computer and use it in GitHub Desktop.
Linux ssh password authentication toggle script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# make a backup copy of the sshd_config file | |
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak | |
# check if the first argument is "enable" or "disable" | |
if [ "$1" == "enable" ]; then | |
# enable password authentication | |
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/; s/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config | |
echo "Password authentication has been enabled" | |
systemctl restart ssh.service | |
elif [ "$1" == "disable" ]; then | |
# disable password authentication | |
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/; s/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config | |
echo "Password authentication has been disabled" | |
systemctl restart ssh.service | |
else | |
# print an error message if the first argument is not "enable" or "disable" | |
echo "Error: Invalid argument. Please specify either 'enable' or 'disable' as the first argument." | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
only tested with debian and ubuntu so far