Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I run a command on a different host? 1

Status
Not open for further replies.

bgreen

Programmer
Feb 20, 2003
185
CA
Hi,

I would like to know how I could run a command from one host on another host.

ex.

On hostname 1 and run a ls command on hostname 2.

is this possible?
 
Install OpenSSH. You should be able to find packages on bull's site.

With keys set up properly, you can do this passwordless.

There are other, insecure, ways of doing it as well.
 
If you are talking about running a single command that requires no user interactive input, like an ls command, the you could use rsh.

You would need to setup a .rhosts file for the user on the remote host that will run the command in the form of:

host username

You will need to set the rhosts permissions to be only read write for the user.

Then you can issue the command from the local host:

rsh remote_host_name ls


A word of caution: using .rhost files is insecure.


 
[ $# -lt 1 ] && set -- ls /var

user=USER
passwd=PASSWORD
host=HOSTNAME

(
sleep 2
echo "$user"; sleep 2
echo "$passwd"; sleep 2
echo "$*"
sleep 2
) | telnet "$host"
 
This would be a single command that I would like to run in a menu.
 
OpenSSH is the way to go.

You can even restrict certain keys (the passwordless method) to the execution of a single command (in this case, ls) by a proper entry in the authorized_keys file of the host2 user that will run it.

Then you'd just:

ssh -l <user> -i <privatekeyfile> host2

to securely execute the remote command. The advantage here is that the private key, if compromised, won't give shell access to host2.

OpenSSH is useful for a lot of other things, as well. Grab it from pick up a copy of SSH The Secure Shell - The Definitive Guide, and you'll never look back.

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L
 
i'll give you a star for that one, rod.

IBM Certified -- AIX 4.3 Obfuscation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top