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

[{'answer_id': 29078, 'author': 'Iker Jimenez', 'author_id': 2697, 'author_profile': 'https://Stackoverflow.com/users/2697', 'pm_score': 0, 'selected': False, 'text': '<p>You can use <a href="https://en.wikipedia.org/wiki/Expect" rel="nofollow noreferrer"><code>expect</code></a> command to populate the username/password info.</p>\n'}, {'answer_id': 29083, 'author': 'Mats Fredriksson', 'author_id': 2973, 'author_profile': 'https://Stackoverflow.com/users/2973', 'pm_score': 6, 'selected': True, 'text': '<p>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</p>\n\n<pre><code>ssh user@host command\n</code></pre>\n\n<p>for example</p>\n\n<pre><code>ssh user@host ls\n</code></pre>\n\n<p>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.</p>\n'}, {'answer_id': 29089, 'author': 'Steve M', 'author_id': 1693, 'author_profile': 'https://Stackoverflow.com/users/1693', 'pm_score': 2, 'selected': False, 'text': "<p>You need to put your SSH public key into the <code>~/.ssh/authorized_keys</code> file on the remote host. Then you'll be able to SSH to that host password-less.</p>\n\n<p>Alternatively you can use <code>ssh-agent</code>. I would recommend against storing the password in the script.</p>\n"}, {'answer_id': 29097, 'author': 'gmuslera', 'author_id': 3133, 'author_profile': 'https://Stackoverflow.com/users/3133', 'pm_score': -1, 'selected': False, 'text': '<p>The easiest way is using a certificate for the user that runs the script.</p>\n\n<p>A more complex one implies adding to stdin the password when the shell command asks for it. Expect, perl libraries, show to the user the prompt asking the password (if is interactive, at least), there are a lot of choices.</p>\n'}, {'answer_id': 29114, 'author': 'Jon Ericson', 'author_id': 1438, 'author_profile': 'https://Stackoverflow.com/users/1438', 'pm_score': 5, 'selected': False, 'text': '<p>First, you need to make sure you\'ve set up password-less (public key login).  There are at least two flavors of ssh with slightly different configuration file formats.  Check the <strong>ssh</strong> manpage on your system, consult you local sysadmin or head over to <a href="https://stackoverflow.com/questions/7260/how-do-i-setup-public-key-authentication">How do I setup Public-Key Authentication?</a>.  </p>\n\n<p>To run <strong>ssh</strong> in batch mode (such as within a shell script), you need to pass a command you want to be run.  The syntax is:</p>\n\n<pre><code>ssh host command\n</code></pre>\n\n<p>If you want to run more than one command at the same time, use quotes and semicolons:</p>\n\n<pre><code>ssh host "command1; command2"\n</code></pre>\n\n<p>The quotes are needed to protect the semicolons from the shell interpreter.  If you left them out, only the first command would be run remotely and all the rest would be run on the local machine.</p>\n'}]
['https://Stackoverflow.com/questions/29061', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1438/']