Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

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

I am trying to run the following command as deploy from Java (the JVM is running as the user tomcat):

sudo -u deploy /path/to/my/bash/script.sh PARAM1 PARAM2

My sudoers file has the following in it:

tomcat ALL=(deploy) NOPASSWD: /path/to/my/bash/script.sh *

But I get sorry, you must have a tty to run sudo in my Java application. Therefore, I changed my invocation to be:

su --session-command="/path/to/my/bash/script.sh PARAM1 PARAM2" deploy

But now I get standard in must be a tty in Java.

I have checked, and by doing the following I can see that sudo doesn't prompt for a password but su does.

[root@mybox bin]# sudo su tomcat
[tomcat@mybox bin]$ sudo -u deploy /path/to/my/bash/script.sh PARAM1 PARAM2
output of script with PARAM1 PARAM2
[tomcat@mybox bin]$ su --session-command="/path/to/my/bash/script.sh PARAM1 PARAM2" deploy
su: incorrect password

Obviously sudoers is only for sudo (hence the name). Is there another way of running the command as deploy without a password prompt?

I am developing this on centos 6.3 but it will eventually be running on RHEL5.

share|improve this question
up vote 3 down vote accepted

You can relax the requiretty setting in the /etc/sudoer.

excerpt from sudoers man page

requiretty      If set, sudo will only run when the user is logged in to a real 
                tty. When this flag is set, sudo can only be run from a login
                session and not via other means such as cron(8) or cgi-bin 
                scripts.  This flag is off by default.

By default this line says everyone must have tty access when using sudo:

Defaults requiretty

You can relax it per user and/or group like this:

$ sudo visudo
# group
Defaults:%group !requiretty
# user
Defaults:user   !requiretty

note: The ! means not.

See the sudo & sudoers man pages for more details.

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.