Bash – How to su to user login shell directly

bashshellsu

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)

Best Answer

This will work:

su -c "su - user2"
Related Question