I am using Fabric to run commands on a remote server. The user with which I connect on that server has some sudo privileges, and does not require a password to use these privileges. When SSH'ing into the server, I can run
sudo -S -p <sudo_prompt> /bin/bash -l -c "<command>"
shell=False to sudo. That way /bin/bash won't be added to the sudo command.
From line 503 of fabric/operations.py:
if (not env.use_shell) or (not shell): real_command = "%s %s" % (sudo_prefix, _shell_escape(command))
the else block looks like this:
# V-- here's where /bin/bash is added real_command = '%s %s "%s"' % (sudo_prefix, env.shell, _shell_escape(cwd + command))