--- title: "使用rmate讓VS Code遠端編輯Raspberry Pi的檔案" description: "經由SSH Tunnel達成遠端編輯程式碼" # image: https://hackmd.io/screenshot.png tags: Raspberry Pi,VS Code # robots: noindex, nofollow langs: zh-Hant --- # 使用rmate讓VS Code遠端編輯Raspberry Pi的檔案 透過VS Code的擴充功能**Remote VSCode**,讓我們可以利用Textmate的**rmate**功能,經由SSH Tunnel達成遠端編輯程式碼。 > 參考: > - [Remote VSCode - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=rafaelmaiolla.remote-vscode) > - [Visual Studio Code remote file edit on Raspberry Pi – K. Rohn´s tech blog](https://rohn.io/visual-studio-code-remote-file-editing-on-raspberry-pi) > - [Live Editing Raspberry Pi files in Sublime Text & RSUB & putty](https://www.martinrowan.co.uk/2015/07/live-editing-raspberry-pi-files-remotely-windows-pc-using-sublime-text-rsub-putty/) ## 本地電腦 ### Remote VSCode 1. 開啓VS Code,點選『擴充功能』並搜尋 **"Remote VSCode"** ,安裝它並重新啟動VS Code 2. 開啓 **檔案>喜好設定>設定**,切換至setting.json並搜尋 **"remote."**會看到以下配置: ```json // If set to true, error for remote.port already in use won't be shown anymore. "remote.dontShowPortAlreadyInUseError": false, // Address to listen on. "remote.host": "127.0.0.1", // Launch the server on start up. "remote.onstartup": false, // Port number to use for connection. "remote.port": 52698 ``` 3. 按下 <kbd>F1</kbd> 開啓命令選擇區執行 **"Remote:Start Server** ### 建立SSH Tunnel #### Linux 開啟終端並輸入: ```bash ssh -R 52698:localhost:52698 <IP Of the Raspberry Pi> ``` #### Windows 使用PuTTY來建立SSH Tunnel。 - Session - **Host name (IP address)** : IP Of the Raspberry Pi - **port** : 22  - Connection > SSH > Tunnels - **Source port** : 52698 - **Destination** : localhost:52698 - **Choose** Remote & Auto  - Open & Login in Raspberry Pi ## Raspberry Pi - 安裝rmate ```bash sudo pip install rmate ``` - 執行rmate並指定完整文件路徑,讓VS Code中遠端開啓該文件 ``` rmate /path/of/your/flie ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up