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 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
add comment

1 Answer

up vote 2 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
add comment

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.