I'm in the process of fixing a script which fails because it invokes sudo in an environment without a pty which has a sudoers file defining Default requiretty.

The script is executed by root and uses sudo to call binaries which depend on being executed by specific users, so my solution was to replace those sudo by su.

Now I want to test my modifications, but I have a hard time reproducing the environment where sudo failed :

  • I can access the machine through another user, then log as root with sudo su -. I don't know root's password.

  • I know how to access the machine without a pty with ssh -T, but then I can't log as root anymore because sudo fails.

How could I get a root shell without pty ?

  • Just for testing, can you edit your sudoers file so that one of your users can run sudo su without entering a password, using the NOPASSWD directive? If you do this and then ssh -T, you may be able to use sudo su to become root without getting a PTY. Jun 15, 2017 at 11:59
  • 1
    It is possible to make exceptions from default requiretty, if you are allowed to do so. unix.stackexchange.com/questions/79960/…
    – VPfB
    Jun 15, 2017 at 12:09
  • I would have preferred avoiding to edit any configuration on the machine but I guess removing the requiretty constraint on sudo su - or making it NOPASSWD should do the trick. I will try this out.
    – Aaron
    Jun 15, 2017 at 12:12
  • 1
    Are you on a Redhat system? They used to ship sudoers with default requiretty, but recently changed that: bugzilla.redhat.com/show_bug.cgi?id=1196451. Maybe that helps you in deciding.
    – VPfB
    Jun 15, 2017 at 12:24
  • 1

1 Answer 1


First thing I'd try is to execute your script with at or cron.


at now <<< "sudo echo 'This will fail if sudoers requiretty' 2>/tmp/stderr >/tmp/stdout" 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .