To log in from host1 to host2, I do the following (someone else set up this, I don't control these machines):
[user1@host1] sudo su - user2
[user2@host1] ssh host2
...so, as I understand it, my user account user1 at host1 is allowed to sudo and change the user to user2, and user2 is allowed to ssh to host2 without having to enter a password. That is simply some set-up some user admin of the systems used to give me access to host2 through my personal user account user1 at host1.
I'd like to script this - so, I want to create a script that can be executed by user1 at host1 to get directly logged in to host2.
I thought a scriptfile at host1 for user user1 with this line in it would do it:
sudo su - -c "ssh host2" user2
...since it should run command "ssh host2" as the new user. But when I execute the above line as user1 at host1, I get the following:
[sudo] password for user1: (entering password)
Sorry, user user1 is not allowed to execute '/bin/su - -c echo foo user2' as root on host1.
...so it seems like that doesn't do what I need - or, this method won't work since I don't have sudo permissions to add the -c argument to su.
Any idea how I can achieve what I want - write a script in order to log into host2 as user1 from host1 as user1 with a script?