How do you use ssh in a shell script?

bash, ksh, rsh, shell, ssh

Solution

Depends on what you want to do, and how you use it. If you just want to execute a command remotely and safely on another machine, just use

ssh user@host command

for example

ssh user@host ls

In order to do this safely you need to either ask the user for the password during runtime, or set up keys on the remote host.

Problem

When I try to use an ssh command in a shell script, the command just sits there. Do you have an example of how to use ssh in a shell script?

Original source