diff --git a/ssh/add_ssh_pubkey/add_ssh_pubkey.sh b/ssh/add_ssh_pubkey/add_ssh_pubkey.sh index 6005aed..713d71b 100644 --- a/ssh/add_ssh_pubkey/add_ssh_pubkey.sh +++ b/ssh/add_ssh_pubkey/add_ssh_pubkey.sh @@ -18,22 +18,22 @@ echo "$SSH_KEY" >> ~/.ssh/authorized_keys chmod 600 ~/.ssh/authorized_keys # 检查并配置sshd_config文件 -SSHD_CONFIG="/etc/ssh/sshd_config" -if grep -q "^#PasswordAuthentication" $SSHD_CONFIG; then - sudo sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication no/' $SSHD_CONFIG -elif grep -q "^PasswordAuthentication" $SSHD_CONFIG; then - sudo sed -i 's/^PasswordAuthentication.*/PasswordAuthentication no/' $SSHD_CONFIG -else - echo "PasswordAuthentication no" | sudo tee -a $SSHD_CONFIG -fi +# SSHD_CONFIG="/etc/ssh/sshd_config" +# if grep -q "^#PasswordAuthentication" $SSHD_CONFIG; then +# sudo sed -i 's/^#PasswordAuthentication.*/PasswordAuthentication no/' $SSHD_CONFIG +# elif grep -q "^PasswordAuthentication" $SSHD_CONFIG; then +# sudo sed -i 's/^PasswordAuthentication.*/PasswordAuthentication no/' $SSHD_CONFIG +# else +# echo "PasswordAuthentication no" | sudo tee -a $SSHD_CONFIG +# fi -if grep -q "^#PermitRootLogin" $SSHD_CONFIG; then - sudo sed -i 's/^#PermitRootLogin.*/PermitRootLogin prohibit-password/' $SSHD_CONFIG -elif grep -q "^PermitRootLogin" $SSHD_CONFIG; then - sudo sed -i 's/^PermitRootLogin.*/PermitRootLogin prohibit-password/' $SSHD_CONFIG -else - echo "PermitRootLogin prohibit-password" | sudo tee -a $SSHD_CONFIG -fi +# if grep -q "^#PermitRootLogin" $SSHD_CONFIG; then +# sudo sed -i 's/^#PermitRootLogin.*/PermitRootLogin prohibit-password/' $SSHD_CONFIG +# elif grep -q "^PermitRootLogin" $SSHD_CONFIG; then +# sudo sed -i 's/^PermitRootLogin.*/PermitRootLogin prohibit-password/' $SSHD_CONFIG +# else +# echo "PermitRootLogin prohibit-password" | sudo tee -a $SSHD_CONFIG +# fi # 重启ssh服务以应用更改 sudo systemctl restart sshd