SSHCommand
SSHCommand copied to clipboard
Unable to natively execute sudo privileged commands
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.
Another observation I've made... if you have an "&" in the password, it fails.
User can write command with echo and pipe if it's necessary.
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