AdSense

網頁

2023/9/6

GCP SSH連線到VM instance

GCP SSH連線到VM instance的方式如下。



建立VM instance

參考「GCP 建立Compute Engine VM instance」建立VM instance。例如VM的public IP為34.81.210.198


VPC Firewall

Instance所在VPC的Firewall rule要設定Ingress允許本機IP(或任意IP 0.0.0.0/0)和TCP:22。這樣本機ssh連線到instance才不會被防火牆阻擋導致Operation timed out。


產生SSH key

參考「Mac 產生SSH金鑰 generate ssh key」產生SSH key。例如產生的SSH key名稱為john,SSH key私鑰路徑為~/.ssh/john_rsa


加入SSH key

參考「GCP Compute Engine VM instance 新增SSH key」加入SSH key到VM instance。


SSH登入VM instance

開啟命令列,輸入ssh <username>@<vm-public-ip> -i <ssh-private-key-path>即可登入VM。例如ssh john@34.81.210.198 -i ~/.ssh/john_rsa

~% ssh john@34.81.210.198 -i ~/.ssh/john_rsa
Linux demo-instance-001 5.10.0-24-cloud-amd64 #1 SMP Debian 5.10.179-5 (2023-08-08) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
john@demo-instance-001:~$



沒有留言:

AdSense