changes
This commit is contained in:
parent
076753e682
commit
c913d1780b
@ -14,7 +14,7 @@ set -e
|
|||||||
export DEBIAN_FRONTEND=noninteractive
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
echo "Upgrade packages..."
|
echo "Upgrade packages..."
|
||||||
apt-get update -y
|
apt-get update
|
||||||
apt-get upgrade -y
|
apt-get upgrade -y
|
||||||
|
|
||||||
echo "Install apps..."
|
echo "Install apps..."
|
||||||
|
42
ssh-pw.sh
42
ssh-pw.sh
@ -5,49 +5,39 @@ if [ "$(id -u)" != "0" ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Проверка наличия одного аргумента
|
|
||||||
if [ "$#" -ne 1 ]; then
|
if [ "$#" -ne 1 ]; then
|
||||||
echo "Usage: $0 <y/n>"
|
echo "Usage: $0 <y/n>"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Проверка аргумента
|
|
||||||
if [ "$1" != "y" ] && [ "$1" != "n" ]; then
|
if [ "$1" != "y" ] && [ "$1" != "n" ]; then
|
||||||
echo "Invalid argument. Use 'y' to enable password authentication and 'n' to disable it"
|
echo "Invalid argument. Use 'y' to enable password authentication and 'n' to disable it"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' EXIT
|
ENABLE_PASSWORD=$1
|
||||||
set -e
|
|
||||||
|
|
||||||
# Путь к конфигурационному файлу sshd
|
|
||||||
SSHD_CONFIG="/etc/ssh/sshd_config"
|
SSHD_CONFIG="/etc/ssh/sshd_config"
|
||||||
|
|
||||||
# Функция включения или отключения доступа по паролю
|
trap 'echo -e "\033[31mSomething went wrong\033[0m"; exit 1' ERR
|
||||||
toggle_password_access() {
|
set -e
|
||||||
local enable=$1
|
|
||||||
if [ "$enable" == "y" ]; then
|
echo "Backup $SSHD_CONFIG..."
|
||||||
sudo sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication yes/' $SSHD_CONFIG
|
cp $SSHD_CONFIG $SSHD_CONFIG.backup
|
||||||
sudo sed -i 's/^PasswordAuthentication no/PasswordAuthentication yes/' $SSHD_CONFIG
|
|
||||||
|
if [ "$ENABLE_PASSWORD" == "y" ]; then
|
||||||
|
sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication yes/' $SSHD_CONFIG
|
||||||
|
sed -i 's/^PasswordAuthentication no/PasswordAuthentication yes/' $SSHD_CONFIG
|
||||||
else
|
else
|
||||||
sudo sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication no/' $SSHD_CONFIG
|
sed -i 's/^#PasswordAuthentication yes/PasswordAuthentication no/' $SSHD_CONFIG
|
||||||
sudo sed -i 's/^PasswordAuthentication yes/PasswordAuthentication no/' $SSHD_CONFIG
|
sed -i 's/^PasswordAuthentication yes/PasswordAuthentication no/' $SSHD_CONFIG
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
# Бэкапим текущий конфигурационный файл
|
echo "Restart SSH for apply password $1"
|
||||||
sudo cp $SSHD_CONFIG $SSHD_CONFIG.backup
|
systemctl daemon-reload
|
||||||
|
systemctl restart ssh
|
||||||
|
|
||||||
# Применение изменений
|
trap - ERR
|
||||||
toggle_password_access "$1"
|
|
||||||
|
|
||||||
# Перезапуск службы sshd для применения изменений
|
|
||||||
sudo systemctl restart sshd
|
|
||||||
|
|
||||||
|
|
||||||
trap - EXIT
|
|
||||||
|
|
||||||
# Уведомление о завершении
|
|
||||||
if [ "$1" == "y" ]; then
|
if [ "$1" == "y" ]; then
|
||||||
echo "Password authentication has been enabled"
|
echo "Password authentication has been enabled"
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user