创建GCP实例。你也可以参考《谷歌云新增实例并关联自定义防火墙规则的方法》
导航菜单 > Compute Engine > VM 实例
区域
我选择的是香港
,因为速度最快,也最为抢手,因此很有可能遇到IP暂时分配不到的情况,建议换个地区
试试。如果是移动的网络的话,延迟有点高,可以考虑其它区域
,比如日本
或者台湾
。机器类型
选择f1-micro
,614MB内存绰绰有余,更大的内存意味着更多的钱。有这些钱,还不如再开一个其它地区的VM实例。启动磁盘
我选择的是默认的Debian 9,只要不是太旧的都行。防火墙
勾选允许HTTP流量
和允许HTTPS流量
点击创建,等待实例创建完成即可。下面开始设置本地SSH客户端连接谷歌云实例。
一、修改ssh配置文件并设置root密码
1.首先使用Google Cloud SSH登录VPS
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j6hvlh6j20sg0ej77z.jpg)
2.切换到root账户
sudo -i
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j6m4rl8j20pe04u0so.jpg)
3.编辑sshd配置文件
vim /etc/ssh/sshd_config
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j6pu9awj20pf059aa2.jpg)
4.修改以下内容即可
按键盘【i】进入编辑,按【Esc】退出编辑,再输入 :wq 保存并退出
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j6up2wkj20ms06cq3a.jpg)
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j6yuwugj20sg04r76b.jpg)
5.重启sshd服务
service sshd restart
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j73ibiyj20nj06lt8l.jpg)
6.为root账户设置密码
passwd
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j78jvgzj20p306jaa6.jpg)
输入密码
输入密码的时候不会显示出来,所以直接输入密码,然后回车,再然后重复输入密码回车
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j7c6t4sj20m208f0t3.jpg)
确认密码 再输入一次
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j7ftqzij20n909oaai.jpg)
设置成功
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j7jclq5j20sg0af430.jpg)
二、用shell工具登录谷歌云实例
1.安装Finalshell连接工具
点击下载Finalshell 下载完成后直接安装就好。
其他的SSH工具也行。
2.打开 Finalshell软件连接服务器
点击 【SSH连接Linux】
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j7tf6z7j20pz0eymxj.jpg)
输入账户和密码
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j7xu7dwj20sg0ddwki.jpg)
双击 登录
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j823y1oj20n70ebdg4.jpg)
点击【接受并保存】
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j865x45j20rt0kfgms.jpg)
连接成功
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j8ajs2jj20rt0kfwfc.jpg)
三、其他方法(原理一样但更快速)
1.sshd配置文件快速修改
用下面的命令改配置文件,然后重启一下sshd服务,然后设置管理员root的密码就可以了。
CentOS和Debian通用
sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
Ubuntu系统
sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
重启SSH服务
service sshd restart
2.为root账户设置登录密码
passwd
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j8g4phvj20p306jaa6.jpg)
输入密码
输入密码的时候不会显示出来,所以直接输入密码,然后回车,再然后重复输入密码回车
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j8jxfr0j20m208f0t3.jpg)
确认密码 再输入一次
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j8nkafyj20n909oaai.jpg)
设置成功
![](https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/c51a3658gy1gq6j8rkm4dj20sg0af430.jpg)
重启SSH服务service sshd restart这个命令现在不用了。
重启SSH:
systemctl restart sshd.service
查看 sshd 服务是否启动:
systemctl status sshd.service