You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
724 B
32 lines
724 B
5 years ago
|
#!/usr/bin/env sh
|
||
|
|
||
|
[ ! "$(id -u)" -eq 0 ] && echo "Run as superuser." && exit 1
|
||
|
|
||
|
case "${1}" in
|
||
|
"on"|"enable"|"unlock")
|
||
|
FROM=yes; TO=no;
|
||
|
;;
|
||
|
"off"|"disable"|"lock")
|
||
|
FROM=no; TO=yes;
|
||
|
;;
|
||
|
"toggle")
|
||
|
if grep -q '^PasswordAuthentication yes' /etc/ssh/sshd_config; then
|
||
|
FROM=yes; TO=no;
|
||
|
else
|
||
|
FROM=no; TO=yes;
|
||
|
fi
|
||
|
;;
|
||
|
esac
|
||
|
|
||
|
for OPTION in PasswordAuthentication ChallengeResponseAuthentication; do
|
||
|
sed -i "s/#* *${OPTION} *${FROM}/${OPTION} ${TO}/g; w /dev/stdout" /etc/ssh/sshd_config
|
||
|
done
|
||
|
|
||
|
if command -v systemctl > /dev/null; then
|
||
|
systemctl restart sshd
|
||
|
elif [ -x /etc/init.d/sshd ]; then
|
||
|
/etc/init.d/sshd restart
|
||
|
else
|
||
|
echo "Restart SSH server to have changes take effect."
|
||
|
fi
|