Paramiko error when trying to edit file: “sudo: no tty present and no askpass program specified”

后端 未结 1 1156
旧巷少年郎
旧巷少年郎 2020-12-06 23:35

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

相关标签:
1条回答
  • 2020-12-07 00:09

    If you read the error message

    sudo: no tty present and no askpass program specified
    

    then you can easily find the solution: add the -t option to your ssh command:

    -t
    Force pseudo-terminal allocation. This can be used to execute arbitrary screen-based programs on a remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.

    This has been discussed before:

    • How to fix 'sudo: no tty present and no askpass program specified' error?
    • sudoers NOPASSWD: sudo: no tty present and no askpass program specified

    Regarding Paramiko, there have been related questions, with a couple of different approaches:

    • use the get_pty method of the ssh Channel to obtain a pseudo-terminal (which is analogous to telling ssh to do this)
    • use the -S option of sudo, and send the password on your standard output.

    For discussion, see the suggested answers here:

    • Paramiko and Pseudo-tty Allocation
    • Nested SSH session with Paramiko
    0 讨论(0)
提交回复
热议问题