Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

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

Note2:
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.

Note3:
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
1  
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
add comment

3 Answers 3

up vote 2 down vote accepted

Ok. :-)

This will work:

su -c "su - user2"

I think that's a little bit faster.

share|improve this answer
add comment

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

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

Your Answer

 
discard

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.