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
posted @ 2020-11-08 21:03  Feng1024  阅读(2047)  评论(0编辑  收藏  举报