vscode远程开发-调试模式下attach远程进程提示管理员权限失败的问题

主机是WIN10,远程机器是Ubuntu20.04,使用attach附加远程进程,示例launch.json文件如下:

   "configurations": [
    {
        "name": "(gdb) 附加",
        "type": "cppdbg",
        "request": "attach",
        "processId":"${command:pickProcess}", 
        "program": "xxx/a.out",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "sourceFileMap":{
            "/AAA/": "/BBB/"
        },
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "/usr/bin/gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ]
    }
]

其中"processId":"${command:pickProcess}"可以使你选择远程进程。但如果你不是以root账户调试,会有下面提示需要管理员权限

com@com-Nuvo-5501:/usr/share/polkit-1/actions$  /usr/bin/env /bin/sh /tmp/Microsoft-MIEngine-Cmd-nkcnhtb0.4ih 
Superuser access is required to attach to a process. Attaching as superuser can potentially harm your computer. Do you want to continue? [y/N]

输入y后不会让你输入密码,直接退出。

解决方案:

参考链接:Remote attach using non-root account would fail directly · Issue #2053 · microsoft/vscode-remote-release · GitHub

在远程机器上新建/usr/share/polkit-1/actions/com.ubuntu.pkexec.gdb.policy   输入以下内容





  
    gdb-settings
    
      yes
      yes
      yes
    
    /usr/bin/gdb
    true
  

这样附加的时候还是会提示要管理员权限,但输入y后不会失败,直接附加

你可能感兴趣的:(vscode)