Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have configured sudo to run without a password, but when I try to ssh 'sudo Foo", I still get sudo: sorry, you must have a tty to run sudo.

Why does this happen and how can I work around it?

share|improve this question

3 Answers 3

up vote 17 down vote accepted

That's because there must be a

Defaults requiretty

in /etc/sudoers or any file it includes.

RedHat systems (RHEL, fedora...) have been known to have that in their default sudoers file. That provides no real security benefit and can be safely removed.

RedHat has acknowledged the problem and it will be removed in future releases.

share|improve this answer

Use the -t flag to ssh to force tty allocation.

$ ssh luci tty
not a tty
$ ssh luci -t tty
/dev/ttys003
$
share|improve this answer

By default, SUDO is configured to require a TTY. That is, SUDO is expected to be run from a login shell. You can defeat this requirement by adding the -t switch to your the SSH as:

ssh -t someserver sudo somecommand

The -t forces allocation of a pseudo-tty.

If you want to perform this globally, modify /etc/sudoders to specify !requiretty. This can be done a a per user, per group or all-encompassing level.

share|improve this answer
    
No, that's not the default. It's only the redhat distribution of sudo that had requiretty in its default sudoers. It will be fixed in newer releases –  Stéphane Chazelas Apr 1 at 20:28
    
@StephaneChazelas +1 for enlightening me that it's largely indigenous to Red Hat and its siblings and another ++ if I could for the current bug report! –  JRFerguson Apr 1 at 20:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.