当前位置:   article > 正文

VScode远程连接调试_vscode远程调试

vscode远程调试
  1. 下载VScode,官网:https://code.visualstudio.com/。
  2. 安装“Remote - SSH”插件,配置免密登录。

一、配置免密登录

  1. Windows下生成密钥对:ssh-keygen 之后一路回车,默认不设密码,默认目录为 ~/.ssh
  2. 部署公钥至Linux,并赋权限
    将id_rsa.pub公钥上传至服务器端~/.ssh目录。
cd ~/.ssh
cat id_rsa.pub >> authorized_keys
sudo chmod 600 authorized_keys
sudo chmod 700 ~/.ssh
  • 1
  • 2
  • 3
  • 4

这项操作可以部署多个公钥,命令会在 authorized_keys 后面追加,而 Linux 公钥验证检测 authorized_keys 文件中的公钥,一个公钥只运行一个用户使用登录。

  1. 检查密钥登陆功能是否开启
  2. 打开 SSH 配置文件
sudo vim /etc/ssh/sshd_config
  • 1
  1. 查看确认下面两项配置
RSAAuthentication yes
PubkeyAuthentication yes
  • 1
  • 2
  1. 完成全部设置,并以密钥方式登录成功后,再禁用密码登录(可选)
PasswordAuthentication no
  • 1
  1. 重启 SSH
sudo service sshd restart
  • 1

二、VSCode远程连接

直接使用Remote - SSH插件连接即可,第一次要输入密码,后面因为有了密钥就不用输入密码了。
如果不行的话可能是生成的公钥id_rsa.pub找不到,(增加)改一下IdentityFile改成公钥路径。

Host 取个名字
  HostName 127.0.0.1
  User root
  IdentityFile "H:\你的公钥路径\id_rsa.pub"
  • 1
  • 2
  • 3
  • 4

三、VSCode远程attach程序

配置launch.json如下,修改"program"参数。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 附加",
            "type": "cppdbg",
            "request": "attach",
            "program": "/home/...",  //这里要程序的绝对路径
            "processId": "${command:pickProcess}",
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-gdb-set scheduler-locking step",
                    "ignoreFailures": true
                },
                {
                    "description": "Enable pretty-printing for gdb",  //不加这个的话看不到STL容器里面元素的数据
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

四、报错分析

1.No space left on device

OUTPUT窗口提示有“No space left on device”,这是因为磁盘不足或者vscode的日志文件太多了,这时候可以清理磁盘文件、手动去服务器上执行:

rm -rf ~/.vscode-server/bin/*
  • 1

再重试即可。

2.Bad owner or permissions on .ssh/config

提示"Bad owner or permissions on .ssh/config",为文件权限错误,将config文件属性->高级->禁用继承->禁用所有继承权限,然后再添加只有本用户有权限。

3.Permissions 0644 for ‘/root/.ssh/id_rsa’ are too open

Permissions 0644 for ‘/root/.ssh/id_rsa’ are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
将id_rsa文件属性->高级->禁用继承->禁用所有继承权限,然后再添加只有本用户有权限。

4.明明已经上传了公钥,每次还是要输入密码

如果之前有别的vscode进程连过远程机器,需要重启下远程服务器的VScode Server,在VSCode点击左下角设置按钮->命令面板->Remote SSH: Kill VS Code Server on Host。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/AllinToyou/article/detail/714130
推荐阅读
相关标签
  

闽ICP备14008679号