谷歌云GCP设置默认SSH开启ROOT权限 一键脚本

在 GCP 的 Debian 服务器里,打开浏览器 SSH 后粘贴执行:

sudo bash -c 'set -e; f=/etc/ssh/sshd_config; cp -a "$f" "$f.bak.$(date +%Y%m%d-%H%M%S)"; mkdir -p /etc/ssh/sshd_config.d; printf "%s\n" "PermitRootLogin yes" "PasswordAuthentication yes" "KbdInteractiveAuthentication yes" "UsePAM yes" > /etc/ssh/sshd_config.d/99-enable-root-password-login.conf; for k in PermitRootLogin PasswordAuthentication KbdInteractiveAuthentication UsePAM; do grep -qiE "^[#[:space:]]*$k[[:space:]]+" "$f" && sed -i -E "s|^[#[:space:]]*$k[[:space:]].*|$k yes|I" "$f" || printf "\n%s yes\n" "$k" >> "$f"; done; passwd root; /usr/sbin/sshd -t; systemctl restart ssh || systemctl restart sshd || service ssh restart; echo "Done. Login with root, port 22."'

执行过程中会让你输入两次新的 root 密码,输入时不显示字符是正常的。

以后换电脑也没关系,只要能进 GCP 浏览器 SSH,把这行重新粘贴执行就行,不依赖本地 .sh 文件。