linux 本地终端 SSH 连接 gcp (Google Cloud Platform ) 配置教程

简介: linux 本地终端 SSH 连接 gcp (Google Cloud Platform ) 配置教程

准备

首先在gcp创建实例

1.设置当前用户的新密码

$ sudo passwd ${whoami} // 下面以 user 代替 ${whoami}
# 输入新密码

2.设置下 root 的新密码

$ sudo passwd root
# 输入新密码

3.在本地生成私钥和公钥

$ cd ~/.ssh
$ ssh-keygen -f myKey
或者
$ ssh-keygen -t rsa -f ~/.ssh/my-ssh-key -C [USERNAME]

Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase): ( 按enter键即可)
Enter same passphrase again: ( 按enter键即可)
Your identification has been saved in myKey.
Your public key has been saved in myKey.pub.
The key fingerprint is:
SHA256:EW7ow1aaaaaf8mNvk user@computer-name.local
The key's randomart image is:
+---[RSA 2048]----+
|=.o+= o .        |
|o+.o+= + .       |
|o.o..oo *        |
|..o+ +o+ o       |
|.oo+  =+S o      |
| o. * o. = o     |
| ..o =  . =      |
|. o.. .    E     |
| . .o.           |
+----[SHA256]-----+
# 此时会生成 公钥 myKey.pub 和 私钥 myKey

4.复制公钥

$ cat myKey.pub
ssh-rsa AAAAaaaaaaaeglRVJzAhNq+W
中间部分省略。。。
dKx8sJ0Rw4aaaaaa845UVp1 user@computer-name.local
# 把这长长的一段复制下来,把其中的 user@computer-name.local 改为你在浏览器 SSH 登入之后的当前用户名 ${whoami}

5.导入公钥

  • 进入谷歌云平台页面 -> 计算引擎 -> 元数据 -> SSH 密钥,粘贴保存
  • 谷歌就会把上面这段 public key 写入到 ~/.ssh/authorized_keys

6.本地通过私钥登录

$ ssh -i myKey user@ip
$ ssh-rsa [KEY_VALUE] [USERNAME]

Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.11.2-041102-generic x86_64)

7.或者通过 SSH 密码验证登录

$ ssh user@ip
Permission denied (publickey).

# 之所以会出现这种情况,因为谷歌默认把密码验证登录关了,需要自行打开
$ sudo vi /etc/ssh/sshd_config
PasswordAuthentication yes 
:wq!

8.改完要重启 ssh 服务

$ sudo service sshd restart

9.再次连接

$ ssh user@ip
user@IP's password: (输入实例用户的密码)
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.11.2-041102-generic x86_64)
目录
相关文章
|
14天前
|
域名解析 负载均衡 网络协议
Linux网络接口配置不当所带来的影响
总而言之,Linux网络接口的恰当配置是保证网络稳定性、性能和安全性的基础。通过遵循最佳实践和定期维护,可以最大程度地减少配置错误带来的负面影响。
46 0
|
17天前
|
监控 安全 网络协议
快速配置Linux云服务器
快速配置Linux云服务器
|
22天前
|
网络安全 Windows
在Windows电脑上启动并配置SSH服务
在Windows电脑上启动并配置SSH服务
44 0
|
26天前
|
开发框架 .NET Linux
【Azure 应用服务】 部署到App Service for Linux 服务的Docker 镜像,如何配置监听端口呢?
【Azure 应用服务】 部署到App Service for Linux 服务的Docker 镜像,如何配置监听端口呢?
|
26天前
|
应用服务中间件 Linux PHP
【Azure 应用服务】App Service For Linux 环境中,如何修改 Nginx 配置中 server_name的默认值 example.com
【Azure 应用服务】App Service For Linux 环境中,如何修改 Nginx 配置中 server_name的默认值 example.com
|
26天前
|
Java Linux Shell
【Azure 应用服务】部署Jar到App Service for Linux,因启动命令路径配置错误而引起:( Application Error 问题
【Azure 应用服务】部署Jar到App Service for Linux,因启动命令路径配置错误而引起:( Application Error 问题
|
4月前
|
数据可视化 定位技术 Sentinel
如何用Google Earth Engine快速、大量下载遥感影像数据?
【2月更文挑战第9天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,批量下载指定时间范围、空间范围的遥感影像数据(包括Landsat、Sentinel等)的方法~
1989 1
如何用Google Earth Engine快速、大量下载遥感影像数据?
|
4月前
|
编解码 人工智能 算法
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
72 0
|
4月前
|
编解码 人工智能 数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
104 0
|
4月前
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
181 0