Home > IT Architecture, Linux, Programming, SHELL, Systems > resolved – sudo: sorry, you must have a tty to run sudo

resolved – sudo: sorry, you must have a tty to run sudo

April 1st, 2014

The error message below sometimes will occur when you run a sudo <command>:

sudo: sorry, you must have a tty to run sudo

To resolve this, you may comment out "Defaults requiretty" in /etc/sudoers(revoked by running visudo). Here is more info about this method.

However, sometimes it's not convenient or even not possible to modify /etc/sudoers, then you can consider the following:

echo -e "<password>\n"|sudo -S <sudo command>

For -S parameter of sudo, you may refer to sudo man page:

-S' The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device. The password must be followed by a newline character.

So here -S bypass tty(terminal device) to read the password from the standard input. And by this, we can now pipe password to sudo.

Problem resolved?


  1. David
    April 8th, 2014 at 19:18 | #1

    Didn’t work for me, had to use su -s /bin/sh -c ‘command’ user

    • April 10th, 2014 at 07:46 | #2

      Hi David,
      If you use su, then you have to know the password for root, and the more secure /etc/sudoers will not functioning by that way. Seems there’s no way to resolve the “sudo: sorry, you must have a tty to run sudo” issue using sudo.

  1. October 12th, 2014 at 23:14 | #1