[CentOS] SSH Remote Execution - su?

Wed Mar 3 21:48:44 UTC 2010
John Kennedy <skebi69 at gmail.com>

On Wednesday 03 March 2010 16:20:21 Tim Nelson wrote:
> Greetings All-
> 
> I'm about to embark on some remote management testing and need a way to
>  login to a remote system running CentOS 4.x/5.x via SSH, su to root (using
>  a password), then execute a command.
> 
> I currently login to the boxes using key based SSH like this:
> 
> ssh -i ~/remote_key admin@$REMOTEIP
> 
> Then, I SU to root. However, if I try to do this automatically like this:
> 
> ssh -i ~/remote_key admin@$REMOTEIP 'su -l'
> 
> I'm getting:
> 
> "standard in must be a tty"
> 
> So, how am I able to remote login using SSH, su to root, then execute a
>  command as root?
> 
> All comments and suggestions welcome. Thanks!
> 
> --Tim
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> http://lists.centos.org/mailman/listinfo/centos
> 
You could use an expect script to ssh to the box then su to root with the 
password. You can have the script ask for the password so it is not hard coded 
or used on the command line. Expect can allow you to interact with the shell 
once you have su'd.
I have used a combination of bash and expect scripting to get stats from 
multiple boxes and it works a treat.
If you need more details/help, let me know.
John