SSHCommand icon indicating copy to clipboard operation
SSHCommand copied to clipboard

Unable to natively execute sudo privileged commands

Open sigmaenigma opened this issue 1 year ago • 3 comments

Hello. I found an issue on line 49 where the command does not include an option to run a command with sudo privileges. I modified your init.py script in HomeAssistant and verified this works. I can do a formal merge request if you'd like:

# If sudo is in the command, pass the password to execute
if 'sudo' in command:
    _, stdout, stderr = client.exec_command(f'echo {password} | sudo -S {command}')
    password = '**redacted**' # Redacting password for the response
else:
    _, stdout, stderr = client.exec_command(command)

I was trying to perform a 'sudo shutdown -h now' or 'sudo apt update' and noticed this failed but I knew I was successfully logging in.

sigmaenigma avatar Aug 27 '24 22:08 sigmaenigma

Another observation I've made... if you have an "&" in the password, it fails.

sigmaenigma avatar Aug 28 '24 03:08 sigmaenigma

User can write command with echo and pipe if it's necessary.

AlexxIT avatar Aug 28 '24 07:08 AlexxIT

Hello. I found an issue on line 49 where the command does not include an option to run a command with sudo privileges. I modified your init.py script in HomeAssistant and verified this works. I can do a formal merge request if you'd like:

# If sudo is in the command, pass the password to execute
if 'sudo' in command:
    _, stdout, stderr = client.exec_command(f'echo {password} | sudo -S {command}')
    password = '**redacted**' # Redacting password for the response
else:
    _, stdout, stderr = client.exec_command(command)

I was trying to perform a 'sudo shutdown -h now' or 'sudo apt update' and noticed this failed but I knew I was successfully logging in.

Was this merged? I was trying some sudo commands for my OctoPi (sudo systemctl restart camera-streamer) so I can have the stream restart if/when a camera fails, but sudo commands no work :(

Edit: Rather than editing the file, I just used the echo command as such echo <PASS> | sudo -S systemctl restart camera-streamer

TheRealFalseReality avatar Jun 04 '25 15:06 TheRealFalseReality