I am using Paramiko to SSH and edit a config file. The file itself needs sudo permissions to edit. This hasn't been a problem so far, as I've just done echo <sudopw> | sudo <command>
for other sudo commands in my script.
When I try to edit this file using sed, though, nothing happens. stderr
produces: sudo: no tty present and no askpass program specified
Here is my code:
stdin, stdout, stderr = client.exec_command
('echo <sudopassword> | sudo sed -i -e \"\\$aAllowUsers\" /etc/ssh/sshd_config)')
I have tried solutions using invoke_shell
but nothing seems to be working. Any solution to edit this file would be helpful.
EDIT: This has been solved! Don't use get_pty
. Use the -S option of sudo right after "sudo".