Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform

1. 通过浏览器连接到实例

直接通过网络浏览器在 Google Cloud Platform 控制台中进行 SSH 连接:

  1. In the Cloud Platform Console, go to the VM Instances page.GO TO THE VM INSTANCES PAGE
  2. In the list of virtual machine instances, click SSH in the row of the instance that you want to connect to.

    Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform
    Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform

通过浏览器连接到实例时需要注意一些事项。如需了解详情,请参阅通过浏览器进行 SSH 连接

 

2. 通过命令行连接到实例

您可以使用 gcloud 命令行工具轻松连接到您的 Linux 实例。gcloud 工具会在您需要时生成和应用新的项目范围的 SSH 密钥,从而为您管理 SSH 密钥。

要连接到您的实例,请使用 gcloud compute ssh 命令:

gcloud compute ssh [INSTANCE_NAME]

其中 [INSTANCE_NAME] 是实例的名称。

现在,您就可以使用终端在您的 Linux 实例上运行命令了。完成操作后,可使用 exit 命令断开与实例的连接。

 

3. 通过SSH命令行连接实例

LINUX 和 OSX 生成新的 SSH 密钥对:

要在 Linux 或 OSX 工作站上生成新的 SSH 密钥对并将其应用于您的项目,请执行以下操作:

    1. 在您的工作站上打开一个终端,并使用 ssh-keygen 命令生成新的密钥对。指定 -C 标志以添加一条带有用户名的注释,该用户是实例中您将要为其应用密钥的用户。该示例创建了一个名为 my-ssh-key 的私钥和一个名为 my-ssh-key.pub 的公钥文件。
      ssh-keygen -t rsa -f ~/.ssh/my-ssh-key -C [USERNAME]

      其中 [USERNAME] 是实例中您将要为其应用该密钥的用户。如果实例中不存在该用户,Compute Engine 将使用您在此命令中指定的用户名自动创建该用户。

    2. 限制对您的 my-ssh-key 私钥的访问,以便只有您才能读取,并且任何人都无法对其执行写入操作。
      chmod 400 ~/.ssh/my-ssh-key
    3. 转到您的项目的元数据页面。转到“元数据”页面
    4. 点击 SSH 密钥以显示项目范围的 SSH 公钥列表。
    5. 点击修改按钮,以便您可以修改项目中的 SSH 公钥。
    6. 使用 cat 命令获取 ~/.ssh/my-ssh-key.pub 公钥文件的内容。
      cat ~/.ssh/my-ssh-key.pub

      终端会以如下格式显示您的公钥:

      ssh-rsa [KEY_VALUE] [USERNAME]

      其中:

      • [KEY_VALUE] 是生成的公钥值。
      • [USERNAME] 是实例中您将要为其应用该密钥的用户。
    7. 复制 cat 命令的输出内容,并将其作为新的条目粘贴到 SSH 密钥列表中。
    8. 在“SSH 密钥”页面的底部,点击保存以保存新的项目范围的 SSH 密钥。
    9. 在本地terminal中,使用ssh命令登录google cloud
      ssh -i ~/.ssh/my-ssh-key [USERNAME]@[EXTERNAL_IP_ADDRESS]

      其中:

      • [USERNAME] 是连接到实例的用户的名称。在创建 SSH 密钥对时,就指定了该 SSH 密钥对的用户名。如果实例具有该用户的有效 SSH 公钥,并且您拥有与之匹配的 SSH 私钥,则您可以以该用户的身份连接到此实例。
      • [EXTERNAL_IP_ADDRESS] 是您的实例的外部 IP 地址。

      申请google cloud 外部IP,可以参看文章:Google Cloud Platform(GCP) VM 固定,静态,外部IP设定

 

在 Windows 工作站上使用 PuTTY 进行连接:

在 Windows 工作站上,您可以使用 PuTTY 工具连接到您的实例。要使用 PuTTY 连接到您的实例,请执行以下操作:

  1. 如果您还没有将任何公钥应用于您的 Cloud Platform 控制台项目,请生成新的密钥对并将其应用于该项目
  2. 下载 putty.exe
  3. 运行 PuTTY 工具。对于本示例而言,只需运行您已下载的 putty.exe 文件即可。系统会打开一个窗口,您可以在其中配置您的连接设置。
  4. 在 Google Cloud Platform 控制台中,找到您要连接到的实例的外部 IP 地址。转到您的实例列表。转到“实例”页面
  5. 在 PuTTY 工具中,在主机名字段中指定您的用户名和您要连接到的实例的外部 IP 地址。在下面的示例中,用户名为 jane_doe,外部 IP 地址为 203.0.113.2
    Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform
    Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform

    按以下格式输入您的用户名和外部 IP 地址:

    [USERNAME]@[EXTERNAL_IP_ADDRESS]

    其中:

    • [USERNAME] 是连接到实例的用户的名称。在创建 SSH 密钥对时,就指定了该 SSH 密钥对的用户名。如果实例具有该用户的有效 SSH 公钥,并且您拥有与之匹配的 SSH 私钥,则您可以以该用户的身份连接到此实例。
    • [EXTERNAL_IP_ADDRESS] 是您要连接到的实例的外部 IP 地址。
  6. 在 PuTTY 窗口的左侧,导航到 Connection > SSH > Auth
  7. 将 Private key file for authentication 字段设置为您的私钥文件的路径。

    Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform
    Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform
  8. 点击 Open 以打开一个将要连接到您的实例的终端。

 

4. 以 root 用户身份连接到实例

默认情况下,公有映像和大多数常见操作系统不允许通过 SSH 进行 root 登录。作为一种最佳做法,/etc/ssh/sshd_config SSH 配置文件已将 PermitRootLogin 参数设置为 no

由于这样默认设置了此参数,因此即使您在项目或实例元数据中为 root 指定了 SSH 密钥,也不能以 root 用户身份连接到实例。如果某个用户需要 root 权限,则可以通过添加 sudo 运行相关命令来获取这些权限。

当然,您可以通过修改root密码的方式(默认root没有密码)来登录root:

sudo passwd
#Enter new UNIX password: 
#and it will change the root password :)
#then to becom root use command
su
#Password:
#type your password and become a root :)

 

5. FileZilla连接 Google Cloud

 

把Linux的私钥文件id_rsa转换成putty的ppk格式

一、下载转换工具PuTTYgen

https://the.earth.li/~sgtatham/putty/latest/x86/puttygen.exe

二、开始转换

1、运行puttygen

Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform
Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform

2、点击Conversions菜单项中的Import key,选择在Linux下生成的id_rsa文件

Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform
Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform

3、在puttygen的界面上点击Save private key按钮就可以把私钥转换为ppk的格式了

 

Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform
Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform
Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform
Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform
Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform
Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform

至此,Linux的私钥文件id_rsa转换成putty的ppk格式完成。

如果您喜欢用命令行:Debian/Ubuntu try…

apt-get install putty-tools
puttygen keyname -o keyname.ppk

Make sure you’ve replaced the “keyname” with your private key filename.

 

6. IntelliJ IDEA连接 Google Cloud

 

 

 

更多参看官方文档:https://cloud.google.com/compute/docs/instances/connecting-to-instance?hl=zh-cn#standardssh

 

本文:Linux:SSH 无密码连接到 Google Cloud 实例, FileZilla连接 Google Cloud, IntelliJ IDEA连接 Google Cloud, google cloud compute instance, google cloud platform

Loading

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.