Remote -SSH to GCP-VM

Remote -SSH to GCP VM

Step 1 install Remote - SSH extenxions

Step 2 google GCP 確定你的VM

Step 3 connect your VS Code ,快速鍵 F1 或 View > Command Palette

Step 4 搜尋Remote - SSH > Remote - SSH: Open SSH Configuration File

Step 4.2打開 使用者配置檔案 /User/codeart/.ssh/config

對應的參數

1
2
3
4
5
# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host remote-ssh-demo // VM的名稱
HostName 35.234.24.25 // 外部IP位址
User wu_peiflower01 // 你的使用者名稱
IdentityFile // 新增一組 Key

Step 6 打開Terminal (終端機) 或 按熱鍵

Step 7 在終端機 cd 到 /User/codeart/ 資料夾下面 建立資料夾 mykeys 產生私錀

1
cd /User/codeart //使用者下的使用者名稱

Step 8 建立一個名叫mykeys新資料夾,放私錀的地方

1
mkdir mykeys

Step 9 cd 到你的mykeys 子目錄下

1
cd mykeys

Step 10 打入以下命令,產生ssh 公錀

1
ssh-keygen -t rsa -f remote-ssh-demo -C wu_peiflower01 -b 2048

Step 11 打入 ls 查詢是否產生 remote-ssh-demo 私錀與 remote-ssh-demo.pub公錀

1
ls

Step 12 把 私錀 加入 到 IdentityFile 底下

1
2
3
4
5
# Read more about SSH config files: https://linux.die.net/man/5/ssh_config
Host remote-ssh-demo
HostName 35.234.24.25
User wu_peiflower01
IdentityFile /Users/codeart/mykeys/remote-ssh-demo // 加到這裡

Step 13 打開remote-ssh-demo.pub 公錀 並復製

Step 14 回到GCP VM 點擊編輯 往下拉到 安全殼層金鑰 新增項目 貼上公錀 按下儲存

Step 15 回到 VS cdoe 設定VS code 讓 VM 連接到你的VS Code ,快速鍵 F1 或 View > Command Palette

搜尋Remote - SSH > Remote - SSH: Connect to Host 並點擊

Step 16 連線中..…點擊Continue

Step 17 測試新增資料夾看看 open folder ,點擊OK

Step 18 點擊 信任

Step 19 測試建立一個web 資料夾, 是否可兩端同步


Remote -SSH to GCP-VM
https://stonetein.github.io/codeArt-TechBlog/2024/07/09/Remote-SSH-to-GCP-VM/
Author
Stone
Posted on
July 9, 2024
Licensed under