VS Code 搭建遠程調試Shell環境(Remote Linux)


安裝Remote Development插件

  1. 在本機安裝Remote Development
  2. 重啟VS Code,看到左側導航新增:『遠程資源管理器』
  3. 在『遠程資源管理器』連接服務器,略

安裝語法提示插件:shellman

  • 本機安裝shellman,略

安裝格式化插件:shell-format(右鍵 -> 格式化文檔(Ctrl + Alt + L))

  1. 在遠程服務器上,VS Code安裝shell-format
  2. 服務器安裝:shfmt(shell-format依賴於安裝shfmt)
  3. 網速好會自動安裝shfmt,否則手動安裝,查看:4
  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

配置免密碼登錄

  1. 在本機上生成ssh秘鑰:
ssh-keygen -t rsa -b 4096 
  1. 在服務器上把公鑰(路徑為:C:\Users<UserName>.ssh\id_rsa.pub)寫入.ssh/authorized_keys

  2. 設置權限

chmod 700 .ssh
chmod 600 .ssh/authorized_keys
  1. 在VS Code編輯配置文件(config):
Host yourdomain.com
  HostName yourdomain.com
  User root
  IdentityFile C:\Users\<UserName>\.ssh\id_rsa


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM