vscode-bash-debug icon indicating copy to clipboard operation
vscode-bash-debug copied to clipboard

Debug script running as root

Open cristea opened this issue 5 years ago • 5 comments

Executables

Version of bash-debug: 0.3.8

Output of following commands (on windows, execute them in Command Prompt or PowerShell):

ann@Ubuntu2004:~/work/setup/can$ code --version
1.45.1
5763d909d5f12fe19f215cbfdd29a91c0fa9208a
x64
ann@Ubuntu2004:~/work/setup/can$ bash -c 'uname -a; for P in bash bashdb cat mkfifo pkill; do echo ---; which -a $P; command $P --version; done'
Linux Ubuntu2004 5.4.0-33-generic #37-Ubuntu SMP Thu May 21 12:53:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
---
/usr/bin/bash
/bin/bash
GNU bash, Version 5.0.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
Lizenz GPLv3+: GNU GPL Version 3 oder jünger <http://gnu.org/licenses/gpl.html>

Dies ist freie Software.  Sie darf verändert und verteilt werden.
Es wird keine Garantie gewährt, soweit das Gesetz es zulässt.
---
bash: bashdb: Befehl nicht gefunden
---
/usr/bin/cat
/bin/cat
cat (GNU coreutils) 8.30
Copyright © 2018 Free Software Foundation, Inc.
Lizenz GPLv3+: GNU GPL Version 3 oder höher <https://gnu.org/licenses/gpl.html>.
Dies ist freie Software: Sie können sie jederzeit ändern und weitergeben.
Es besteht KEINE GARANTIE, soweit gesetzlich zulässig.

Geschrieben von Torbjorn Granlund und Richard M. Stallman.
---
/usr/bin/mkfifo
/bin/mkfifo
mkfifo (GNU coreutils) 8.30
Copyright © 2018 Free Software Foundation, Inc.
Lizenz GPLv3+: GNU GPL Version 3 oder höher <https://gnu.org/licenses/gpl.html>.
Dies ist freie Software: Sie können sie jederzeit ändern und weitergeben.
Es besteht KEINE GARANTIE, soweit gesetzlich zulässig.

Geschrieben von David MacKenzie.
---
/usr/bin/pkill
/bin/pkill
pkill von procps-ng UNKNOWN

Debug output

Paste here outputs in DEBUG CONSOLE (ctrl+shift+D or command+shift+D) with "showDebugOutput": true and "trace": true in launch.json. Your launch.json may looks like:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "bashdb",
            "request": "launch",
            "name": "Bash-Debug (hardcoded script name)",
            "cwd": "${workspaceFolder}",
            "program": "/home/ann/work/setup/can/can_test.sh",
            "args": []
        }
    ]
}

Details

This shell script has to be run as root. I tried to put sudo infront of the program path but it did not work. How can I debug the script running as root?

cristea avatar Jun 03 '20 06:06 cristea

You can try running the vscode as root, or change your script to run sudo in the lines that need it. Choosing interactive console will allow to input password in second case.

rogalmic avatar Jun 03 '20 15:06 rogalmic

Running vscode as root is not recommended and in my case, just doesn't work at all. Here's other solutions I've tried that don't work:

  • Setting the program to be 'sudo <myScript.sh>'
    • Bashdb can't step through
  • Changing the bashdb path to a script that runs bashdb with sudo (passing through all arguments given)
    • Console outputs a bunch of /tmp/vscode-bash-debug-fifo-#####: Permission denied
  • Doing the previous step and adding chmod a=rwx "${fifo_path}" and chmod a=rwx "${fifo_path}_in" to this spot
    • Same as before

A proper solution would be appreciated.

AZMCode avatar Jun 22 '21 17:06 AZMCode

Personally I use sudo like that: https://raw.githubusercontent.com/rogalmic/vscode-bash-debug/gif/images/bash-debug-samp-stdin-usage.gif

Script does not require root, it will ask for password first time it's needed.

rogalmic avatar Jun 23 '21 06:06 rogalmic

While that may be fine for small scripts, putting sudo in every line of a 100-line script might be cumbersome.

Nevermind if the script has long-running commands that will time out sudo, requiring you to enter the password again in the middle of the script.

Also, if the script input and output happen in the debug output tab (as is default) the password is not masked and it is kept as part of the command history, which is very not good.

AZMCode avatar Jun 25 '21 10:06 AZMCode