Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 want to redirect the output of a local command (using local files) to a remote command.

I know doing something like this is possible:

[user@local ~]$ head -c 5 /dev/urandom | ssh server@ "cat"

... but I would like to know if there is a way to do this via the SSH console, just like the scp command that refers both local and remote files:

[user@remote ~]$ scp test.txt remote:/new.txt

Copying the local file to the remote server is undesirable, I would just like to redirect output.

** Both machines run Linux (bash).

share|improve this question

I think the best way is to redirect the output to a file and then scp that file to the remote host and then you can run the cat command there.

$ head -c 5 /dev/urandom > random && scp ./random user@remoteip:/path/. && cat /path/random

Hope this will satisfy your needs. Reply if it don't.

share|improve this answer
I am upvoting even though the OP said that this isn't what he wants. So long as he doesn't need active streaming (by his example, he doesn't), this should be the most straightforward method. – dotancohen Jun 5 '14 at 6:55

This sounds similar to this question:

So, it looks like the consensus is to set up an inverted ssh session with the -R option, and run the stdout through that.

share|improve this answer

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.