www.question-defense.com | Engage: Visit :: Login :: Register

I was recently working on a Perl script that would SSH to another server and run a sudo command on the remote server that was failing. The error that was received is below.

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

The reason for this is an update along the way with sudo locked it down further by adding the below line to /etc/sudoers configuration file.

Defaults requiretty

To allow a remote script to login and run a command via sudo simply comment out that line as shown below.

# Commented out so remote script can login and run a command without a tty
# Defaults requiretty

I would suggest making a comment in the sudoers file along with the actual script that is running just in case there is another systems administrator that is tasked with working on this server at a later date. Now when your script runs it will not throw that error and should be able to run the remote command that was initially required.

Related posts:
  1. sudo: unable to resolve host I ran in to the weirdest error today.   “sudo: unable...
  2. Compiling ruby on OS X 10.5: readline.c:703: error: ‘filename_completion_function’ undeclared When compiling Ruby 1.8.6 (in this case, p287) on OS...
  3. TFTP: Error code 1: File not found You may get the below error code when attempting to...
  4. pg_restore: [custom archiver] out of memory Recently I was troubleshooting an issue with a Peprl script...
  5. Ubuntu Exim Email Error: R=nonlocal: Mailing to remote domains not supported While working on a clients computer yesterday I needed to...

Tags: , , , , , , ,
43 Responses to “sudo: sorry, you must have a tty to run sudo”
  1. wcarlson says:

    Note: this means cron jobs that say use sudo on the localbox ONLY are not impacted (as no one is typing a password anyway). For example, a cron job that runs vgs to check volume group space.

    sudo -u blah vgs is safer than making a binary suid root, IMO.

    [Reply]

    alex Reply:

    Hello wcarlson,

    Thanks for taking the time to leave feedback.

    Thanks.
    alex

    [Reply]

  2. meanguy says:

    instead of tinkering with the requiretty setting (which can result in printing the root password to the screen) use

    $ ssh -t …

    [Reply]

    alex Reply:

    Hello meanguy,

    Thanks for the opinion. It has been suggested numerous times in the comments. Stay mean!

    Thanks.
    alex

    [Reply]

  3.  
Leave a Reply