sudo requires a
tty to read the password that you'll have to key in or it will throw the
sudo: no tty present and no askpass program specified error. This normally happens such as when automating a script via
SSH as in the following example;
$ ssh [email protected] -- sudo ls [email protected]'s password: sudo: no tty present and no askpass program specified
sudo could also throw the following error, depending on the version.
sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper
The error can be fixed by either via
$ ssh -t [email protected] -- sudo id [email protected]'s password: [sudo] password for user: uid=0(root) gid=0(root) groups=0(root) Connection to example.com closed.
-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 implement- ing menu services. Multiple -t options force tty allocation, even if ssh has no local tty.
sudoto read the password from stdin by using
$ ssh [email protected] -- sudo -S id [email protected]'s password: [sudo] password for user: pass uid=0(root) gid=0(root) groups=0(root)
Your password will be displayed on the
stdout and could pose a securitk risk.
pass is the password in this example.
-S, --stdin Write the prompt to the standard error and read the password from the standard input instead of using the terminal device.
Comment anonymously. Login not required.