How to ssh as root to a workstation and then run commands as another user.
Senario is we have a system where root has authorised keys set up so that it can do a passwordless ssh to $WORKSTATION. I then need to run a script on $WORKSTATION as user "bob" and NOT as user "root". I do not want to set up user "bob" to be allowed passwordless ssh so any ideas how I can do this?
I have tried variations of (as user "root"): ssh $WORKSTATION "su - bob; ./my_script" Just hangs unfortunately. Thanks |
ssh $WORKSTATION 'su - bob -c "$PWD/my_script"'
|
ssh $WORKSTATION 'su - bob -c "$PWD/my_script"' appears to run the command on the local machine as it says it cannot find the script which is located on the $WORKSTATION.
Should the command be: ssh $WORKSTATION 'su - bob -c "$WORKSTATION:/my_script"` Thanks |
No, the command should not be that. Try providing the fully qualified path (rather than a relative path) for your script.
example: /foo/bar/my_script |
I think the $PWD is getting read before the ssh cmd is issued.
You'll have to check the bash docs for order of interpolation. Using $WORKSTATION won't change that. If the script is in a constant place, just use the absolute value of the path, or set it as a variable (maybe an input var) in the call to the script that runs ssh. |
Code:
ssh $WORKSTATION "su -c <command> bob" |
All times are GMT -5. The time now is 11:41 PM. |