Google Cloud VPS DD 重装系统与 Root 登录配置完整教程

本文介绍在 Google Cloud(GCP) 云服务器上进行系统重装 (DD) 的方法,以及如何开启 root 登录权限。适用于 Debian 、 Ubuntu 及 Windows 系统环境。

一、系统初始化

在新建实例或 SSH 连接进入系统后,首先更新软件源并安装基础工具:

Bash
apt update -y && apt install -y wget sudo

二、 DD 方法 (reinstall 脚本)

该脚本支持更多系统类型,包括 Linux 和 Windows 。

1. 下载脚本

海外环境:

Bash
curl -O https://raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh

国内加速:

Bash
curl -O https://gh.kejilion.pro/raw.githubusercontent.com/bin456789/reinstall/main/reinstall.sh

2. 安装 Linux 系统

Bash
bash reinstall.sh debian 12

bash reinstall.sh ubuntu 22.04

3. 支持的常见系统

  • Debian:10 / 11 / 12
  • Ubuntu:20.04 / 22.04 / 24.04
  • CentOS:7 / 8 / 9(8 、 9 为 Stream)
  • Rocky Linux:8 / 9
  • AlmaLinux:8 / 9
  • Fedora:38 / 39 / 40
  • Alpine:3.16 ~ 3.19
  • 其他:Arch 、 Kali 、 Gentoo 、 openSUSE

4. 安装 Windows 系统

Bash
bash reinstall.sh windows --image-name 'Windows 7 Ultimate' --lang zh-cn

1. 常用 Windows 版本

  • Windows 7 Ultimate
  • Windows 10 Enterprise LTSC 2021
  • Windows 11 Pro
  • Windows Server 2022 Datacenter
  • Windows Server 2025 Datacenter

2. 默认登录信息

系统用户名密码
Linuxroot123@@@
Windowsadministrator123@@@

三、系统更新 (重装完成后)

执行更新依赖和系统补丁

Bash
apt update -y && apt full-upgrade -y && apt install -y curl wget sudo socat

7. 项目地址

https://github.com/bin456789/reinstall

五、 GCP 原版系统开启 Root 登录

默认情况下,Google Cloud 出于安全考虑:

  • 禁止 root 直接登录
  • 禁止 SSH 密码认证
  • 推荐使用普通用户 + SSH Key

如果需要开启 root 登录,请按照以下步骤操作。


1. 切换到 root 用户

Bash
sudo -i

2. 设置 root 密码

Bash
passwd

3. 修改 SSH 配置文件

Bash
nano /etc/ssh/sshd_config

找到并修改以下内容:

Bash
PermitRootLogin yes
PasswordAuthentication yes

说明:SSH 配置是从上到下读取,后面的配置会覆盖前面的设置。


4. 检查子配置文件 (重要)

在 GCP 环境中,可能存在额外配置覆盖主配置:

Bash
grep PasswordAuthentication /etc/ssh/sshd_config.d/*

如果看到类似:

Bash
PasswordAuthentication no

需要修改对应文件为:

Bash
PasswordAuthentication yes

5. 重启 SSH 服务

Bash
systemctl restart ssh

六、注意事项

  1. Google Cloud 可能通过 cloud-init 自动覆盖 SSH 配置
  2. 必须确保防火墙已放行 SSH 端口 (默认 22)
  3. 开启 root 密码登录存在安全风险,建议仅在必要时使用