GCP(Google Cloud Platform)是 Google 自研的云计算平台,当购买云主机后会碰到如何远程 SSH连接的问题,因此编写该文档用于为新手简化操作。
方法有很多种,这里介绍几个常见的,本次的环境采用 `Ubuntu 18.04 LTS` 系统进行说明:
点击 SSH

等待上传私钥

登录成功

执行命

涉及命令如下:
修改 sshd 配置
# 提权
sudo -i
# 允许root登录
sed -i 's/PermitRootLogin no/PermitRootLogin yes/' /etc/ssh/sshd_config
# 允许密码认证
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config
检查配置是否修改
# 查看修改是否生效
egrep --color '(PermitRootLogin|PasswordAuthentication)' /etc/ssh/sshd_config
确保如下的配置取消注释:
PermitRootLogin yes
PasswordAuthentication yes
# PasswordAuthentication. Depending on your PAM configuration,
PermitRootLogin yes
设置root密码,并重启ssh服务
# 设置root密码
passwd root
# 重启sshd服务
systemctl restart sshd
说明: 以下的方式均需要用到证书,因此需要先生成证书。
生成证书

说明:并复制公钥内容,自行找到自己的目录下面
.pub结尾的文件,并复制里面的内容即可,我这里的路径是~/.ssh/ssh_gcp_iopssre.pub
点击元数据

点击修改

添加公钥
保存

查看公钥信息
保存成功后,可以看到登录的用户名

回到实例页面
然后创建虚拟机时会自动注入
回到GCP 点击要远程登录的云主机

点击修改

滚动到安全与访问权限
新增一个公钥,并把刚才复制的公钥内容粘贴进去即可

点击保存即可。
调整为证书模式

浏览公钥,保存即可


