The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 09-29-2006
rowan_sen rowan_sen is offline
Registered User
  
 

Join Date: Sep 2006
Posts: 9
From a script on server1, you can run "ssh [user]@server2 [command]" and whatever is in [command] will execute on server2 as user [user].

You will be prompted for a password unless you set up public keys, which basically involves:
(Presume user running script on server1 is "fred" and logs in as "bob" on server2 to run commands listed in fred's script on server1.)
Run "ssh-keygen -t dsa" as whatever user uid the script will run from on server1 (fred). Press [enter] when prompted for passphrase (twice).
Copy ~fred/.ssh/.id_dsa.pub to ~bob/.shh/authorized_keys on server2.

Run "ssh server2 date" from fred's shell on server1 to confirm that you can log in as bob on server2 via ssh without a password. The first time you might have to reply with "yes" so that's another reason to test manually first.

If login fails (if it asks for a password) you might have to change permissions on ~bob/.ssh* on server2 to whatever the sshd server requires. Checks logs to confirm this.