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 two users dev and tomcat neither of them have a password.

How can I allow dev 1 do su - tomcat without having him having to enter any credentials?

1 connects with ssh keyfile

share|improve this question

4 Answers 4

If what you want is to allow dev to run arbitrary commands as tomcat, then don't bother with su, stick with sudo. Add the following line to the sudoers file (use the visudo command):

dev ALL = (tomcat) NOPASSWD: ALL

Run sudo -iu tomcat as the user dev to run a login shell as tomcat.

share|improve this answer

You have sudo added to your tags. In your sudoers file, you can add dev to allowed users and, if you wish, restrict which commands they're allowed to run, and that password isn't required. Then all they'd have to do is type "sudo su - tomcat".

Run visudo to add the following line:

dev ALL = NOPASSWD: /usr/bin/su - tomcat

There's lots more information and examples in the man file for sudoers.

share|improve this answer
still asks for the dev password –  Nifle Aug 28 '12 at 18:14
@Nifle There was an error in the sudoers line, try now. –  Gilles Aug 28 '12 at 23:25
@Gilles - still asks for a password. And had to add ALL=(ALL) to get it to run at all –  Nifle Aug 29 '12 at 3:52
@Nifle Oh, oops, still not right, I forgot the host column. Er, you realize that while sudo won't ask for credentials if you specify NOPASSWD, su is likely to ask for one? –  Gilles Aug 29 '12 at 11:33
up vote 1 down vote accepted

This is how I ended up doing it.

I created the file /etc/sudoers.d/dev


# allow user dev to become user tomcat
# invoked with [dev@host ~]$ sudo su - tomcat
dev ALL = (root) NOPASSWD: /bin/su - tomcat

changed the file permissions with chmod 0440 /etc/sudoers.d/dev

created an alias in dev's .bashrc alias tomcat='sudo su - tomcat'

This results in the ability for the dev user to become the tomcat user without either having to type (or indeed having) a password ever by typing tomcat at the command line.

share|improve this answer

I am not sure but what will happen if you set password for both of them ? Once they have password, you can share the RSA keys for password-less ssh login

share|improve this answer
not having passwords is the point –  Nifle Aug 29 '12 at 13:21

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.