安裝Remote Development插件
- 在本機安裝Remote Development
- 重啟VS Code,看到左側導航新增:『遠程資源管理器』
- 在『遠程資源管理器』連接服務器,略
安裝語法提示插件:shellman
- 本機安裝shellman,略
安裝格式化插件:shell-format(右鍵 -> 格式化文檔(Ctrl + Alt + L))
- 在遠程服務器上,VS Code安裝shell-format
- 服務器安裝:shfmt(shell-format依賴於安裝shfmt)
- 網速好會自動安裝shfmt,否則手動安裝,查看:4
- 進入安裝shfmt,下載shfmt_v3.0.1_linux_amd64,復制到服務器,並在服務器執行
# 把shfmt_v3.0.1_linux_amd64移動到/root/.vscode-server/extensions/foxundermoon.shell-format-7.0.1/bin(具體路徑可在VS Code查看)
mv shfmt_v3.0.1_linux_amd64 /root/.vscode-server/extensions/foxundermoon.shell-format-7.0.1/bin
# 添加權限
chmod a+x /root/.vscode-server/extensions/foxundermoon.shell-format-7.0.1/bin/shfmt_v3.0.1_linux_amd64
安裝語法錯誤檢查插件:shellcheck
- 在遠程服務器上,VS Code安裝shell-format
安裝語法錯誤檢查插件:Code Runner
- 在遠程服務器上,VS Code安裝Code Runner
配置免密碼登錄
- 在本機上生成ssh秘鑰:
ssh-keygen -t rsa -b 4096
-
在服務器上把公鑰(路徑為:C:\Users<UserName>.ssh\id_rsa.pub)寫入.ssh/authorized_keys
-
設置權限
chmod 700 .ssh
chmod 600 .ssh/authorized_keys
- 在VS Code編輯配置文件(config):
Host yourdomain.com
HostName yourdomain.com
User root
IdentityFile C:\Users\<UserName>\.ssh\id_rsa
