Super User is a question and answer site for computer enthusiasts and power users. 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

I do the following many times a day

I login to a server via ssh as user1,
I then do su - to become root,
then I do su --login user2 to become user2

Is there a way to tell su to go to user2 directly from user1?

user21 does not have a password. user2 is named different at different times. (apache, liferay, solr, ftp, ...)

user1 is not trusted with sudo it's a general purpose account used mainly to access logs. It doesn't even have a password, access granted only with a sshkey only.

NO solutions that means any modification of the remote computer allowed. I have 30+ servers that I admin.

1 If you are curious it's the user an application runs as (tomcat, apache, jetty or similar)

share|improve this question
Try su - -c "su - user2" – Keith Apr 21 '11 at 8:19
@Keith - You should post that as an answer as it is precisely what I'm looking for. – Nifle Apr 21 '11 at 10:38
up vote 3 down vote accepted

This will work:

su -c "su - user2"
share|improve this answer

You could use 'sudo' instead of 'su'.

Allow user1 to run the shell command (/bin/bash?) as user2 (in the sudoers file - edit with visudo):

user1 ALL=user2 /bin/bash

Then you can (as user1) do:

$ sudo -u user2 /bin/bash
share|improve this answer
Should have mentioned that sudo isn't an option. user1 is a user many people have access to (it's used to inspect logs mostly). I don't want them to have access to user2 – Nifle Apr 21 '11 at 10:37

I'm pretty sure you can perform:

sudo su user2

All you're doing is moving to root to have the privilege to access that account, you can skip a step but will still need to provide root credentials.

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.