From c37f857d87e13f3b5e7dd5c08d773753f7035ab4 Mon Sep 17 00:00:00 2001 From: Randall Date: Sun, 27 Apr 2025 22:44:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ssh/add=5Fssh=5Fpubkey/add?= =?UTF-8?q?=5Fssh=5Fpubkey.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ssh/add_ssh_pubkey/add_ssh_pubkey.sh | 30 ++++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) 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