Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I execute shell, but it is carried out by cron "sudo: sorry, you must have a tty to run sudo" appears. but how should this have dealt?

share|improve this question
up vote 1 down vote accepted

You don't need sudo to run programs as other users in cron (at least with the system crontab).

Just change the user field from root to the target user.

If you really want su does work in cron.

share|improve this answer
Nice!! I get It!, but "you must have a tty to run sudo" what ? what's tty? – freddiefujiwra May 27 '09 at 2:24
Historically, tty is "teletype". Really the error means that sudo can only be run from an interactive shell. For example, a shell receiving its input from a teletype. – Kevin Beck May 27 '09 at 3:45

You can also simply reconfigure sudo to not require a tty by:

Editing (as root) the file


And commenting out the line that says:

Defaults requiretty
share|improve this answer

You can add NOPASSWD: to the relevant entry in the sudoers file to stop it asking for a password, which I think will help.

You're better off running it from the crontab of the desired user in the first place, and avoiding the need for sudo.

To edit fred's crontab:

su - fred
crontab -e
share|improve this answer

Your Answer


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.