Thursday, December 12, 2013

ssh to server run script

www.unixbabuforum.inI'm looking for a way using a script to login using ssh to a server run a script as root, exit and move on to the next server run the same script move on etc. I know I can do it using trusted ssh keys for root but I can't use trusted keys in this environment so I would have to login using a user name, become root and run the script. I've heard pyton might be able to do this but I have not checked. Does anyone have a suggestion?


www.unixbabuforum.inThere are multiple ways to do this. I would suggest using of sudo on the client side to limited root authority. This way you can use simple ssh -l user_name servername sudo /path_to_script. If you aren't aloud to use sudo or the list of commands is to extensive, then you need something like expect, perl expect, perl net-ssh, or similar python or ruby modules to allow you to write interactive scripts.


www.unixbabuforum.inThere are two steps involved in the requirement: 

1) to login non-interactively to remote clients without using ssh keys; 
2) to execute a script on the remote system using root credentials. 

For step 1, you may use expect. 

For step 2, you can use either sudo or RBAC on the remote systems.

0 comments:

Post a Comment

 
Design by BABU | Dedicated to grandfather | welcome to BABU-UNIX-FORUM