Monday, January 17, 2011

Ssh

I'm writing a Bash script that must be able to run a script on a remote host.  The specific requirements are the following-

1)Login to a remote Linux host.
2)Use Ssh keys for authentication.
3)Execute a script.
4)Logoff.

The script runs as a different userid than my login.  Ssh keys are used for authentication.  I've ran into a couple of problems getting the script to work.  Here's how I solved them.

-i Use a specific identity file.  The file can be owned by a user different from the one executing the script. 

-t-Forces pseudo-tty allocation.  Used to execute arbitrary screen-based programs on a remote host.

-v Verbose mode.  Causes ssh to print debugging messages about its progress.


Here's the line of code looks that accomplished my three objectives.  The -v switch was extremely useful for debugging during numerous code revisions.

/usr/bin/ssh -i /home/myuserid/.ssh/id_rsa -t user@remotehost.domain.com/home/user/home/dbquery.sh

No comments: