连接到 Linux 实例
创建 Linux 实例后,可以通过完成以下步骤来连接到该实例。
查找浮动 IP 地址
如果尚未将浮动 IP 与实例关联,请遵循 使用 CLI 创建实例 中的步骤 3 和步骤 4 来请求要与实例关联的浮动 IP 地址。
如果需要查找要连接到的实例的浮动 IP 地址,请完成以下步骤。 如果您已经知道浮动 IP 地址,请跳至连接。
-
您需要标识浮动 IP 地址。 运行以下命令来确定您的浮动 IP 地址:
ibmcloud is instance-network-interfaces <INSTANCE_ID> <NETWORK_INTERFACE_ID> --json对于此示例,您会看到类似于以下输出的响应:
"floating_ips": [ { "address": "123.45.678.90" "crn:v1:mydomain:public:vpc:us-south:a/c4cxxxc10xx54xxx9e2xxx59xxx3fa0f::floating_ip:12345x67-8901-234x-5678-9xx01xx23x4x", "href": "https://us-south.myaccount.cloud.ibm.com/v1/floating_ips/12345x67-8901-234x-5678-9xx01xx23x4x", "id": "0738-12345x67-8901-234x-5678-9xx01xx23x4x", "name": “my-instance” } ] -
既然您已知道了浮动 IP 标识,那么可以通过运行以下命令来查找浮动 IP 地址。
ibmcloud is ip <FLOATING_IP_ID>对于此示例,您会看到类似于以下输出的响应:
ID 0738-12345x67-8901-234x-5678-9xx01xx23x4x Address 123.45.678.90 Name my-instance Target primary(1xx2x34x-.) Target Type intf Target IP 12.345.6.78 Created 1 week ago Status available Zone us-south-1 Resource Group - Tags -
(可选)可以通过 IBM Cloud 控制台来查找与要连接到的实例关联的浮动 IP 地址。
确定默认用户账户
系统生成的默认用户账户通常用于管理访问和操作。 默认用户可用于通过SSH登录虚拟服务器实例。 SSH 密钥只为映像中的默认用户配置。 默认用户账户的名称取决于所使用的操作系统镜像。 操作系统及其对应的默认用户账户请参见下表。
有关 SSH 密钥的更多信息,请参阅 SSH 密钥入门。
| 操作系统 | 默认用户账户 |
|---|---|
| Red Hat Enterprise Linux (RHEL) | vpcuser |
| Red Hat Enterprise Linux (RHEL) AI | cloud-user |
| SUSE Linux Enterprise Server (SLES) | vpcuser |
| Debian | vpcuser |
| Rocky Linux | vpcuser |
| CentOS Stream | vpcuser |
| Ubuntu | ubuntu |
| Fedora CoreOS | core |
连接
-
要连接到实例,请使用专用密钥并运行以下命令:
ssh -i <path to your private key file> <default-user-account>@<floating ip address>您会收到类似于以下示例的响应。 系统提示您继续连接时,请输入
yes。The authenticity of host 'xxx.xxx.xxx.xxx (xxx.xxx.xxx.xxx)' can't be established. ECDSA key fingerprint is SHA256:abcdef1Gh/aBCd1EFG1H8iJkLMnOP21qr1s/8a3a8aa. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'xxx.xxx.xxx.xxx' (ECDSA) to the list of known hosts.您现在正在访问服务器。
-
准备好结束连接时,请运行以下命令:
exit