[VsCode] 藉由 Remote-SSH 連接 Linux
學習目標
透過VsCode套件Remote-SSH如何連接到Linux。
目錄
一、前言
在測試Oracle Cloud的時候有提供免費方案可以架設VPS,剛好藉此機會來玩一下透過VsCode要如何SSH遠端,單純使用SSH遠端的方式有很多種,之前在工作中往往都是透過Putty+WinSCP來完成相關需求,這次只是單純想要試試不同的工具看看有沒有新的發現。
二、基本設定
SSH KEY
可以使用PuTTYgen協助生產,至於這邊部分因為我們是使用OracleCloud上的主機,這邊在OCI上面自己生產,位子如下圖:
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
VsCode
這邊我們是使用Remote - SSH套件,直接在VsCode搜尋後安裝即可
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
安裝完成後UI上面會多了一個功能(圖#1),這邊我們直接點擊功能業內的+號來新增連線
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
點擊後會跳出視窗,這邊輸入對應的使用者和連線位置之後即可
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
這時會跑出要你選擇SSH Config的路徑,這邊我們直接選預設路徑就好了
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
完成後UI會跳出所設定好的連線
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
基本上到這一步算是基本的建立都已經完成了,接下來要來進行設定私鑰
Pirvate Key
在連線中我們想要使用私鑰進行認證這邊提供兩種方式
.ssh
將私鑰直接放置對應的位置即可,在連線時會自動檢查
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
SSH config
我們也可以真對SSH config做些設定,這邊我們點選齒輪後續依樣使用預設的路徑(如下圖)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
之後會打開一份文件即是SSH的設定檔
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
這邊我們增加了一個IdentityFile
的設定用來直接指定私鑰
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
相關設定的參考可參考網址 ssh_config
三、連線操作
要連線時可以對該設定點選右鍵或點選右方的小圖即可
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
連線成功後左下角也可以看到相關資訊
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
透過工具也可以針對資料夾作連動,在連線狀態下我們前往資料夾頁面,並點選開啟資料夾
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
之後畫面會跳出路徑設定,這邊選擇想要操作的資料夾即可
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
確定後VsCode就會顯示內部的資料夾
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
結論
這次正好有時間來玩一下不同的工作使用SSH連接,整體測試下來還算蠻滿意的,以往會需要Putty+WinSCP來做切換才可完成任務,但在之後工作上或許可以在VsCode就完成,對我來說算是不錯的選擇。
相關參考來源:
Visual Studio Code 使用 Remote - SSH 開啟遠端 Linux 資料夾