Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking to, all in the course of one batch file:

  1. ssh into a remote computer
  2. execute commands (per the batch file) on the remote host.

What options do I need to add to the ssh invocation so that the batch file executes the lines following the ssh invocation over the connection?

e.g., with sftp it's simply adding a -b /dev/stdin and then << EOF at the end; how do I do this with SSH?

share|improve this question
up vote 4 down vote accepted

You can just run

ssh machine_name <

to run all commands in on machine_name. Works with at least OpenSSH. If you want to enter those commands by yourself before opening ssh, you can use

ssh machine_name << EOF
share|improve this answer
Awesome---is there a way to throw literal commands through the pipe? – invaliduser Feb 17 '11 at 20:14
Of course. You can use exactly same as with sftp; just write for example cat << EOF | ssh machine_name, write your commands and press ctrl+D (EOF) – Olli Feb 17 '11 at 20:16
Here's a Useless Use of cat Award for you. (ssh < and ssh <<EOF) – grawity Feb 17 '11 at 21:55
@grawity Thanks, I updated, my answer. – Olli Feb 18 '11 at 7:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.