How to remotely write to a file using SSH


I can copy a file to a remote Linux machine with no problem with

scp file user@host: /pathtowrite_file

However, I'm having difficulty writing to a file from one linux machine to another. Here is what I attempted:

echo 'Some Text' > /remotefile.txt | ssh user@remotehost

The notice that I get is

stdin: is not a tty

At any rate, the file on the remote machine does not reflect the text sent 'Some Text'.

Best Answer

You can use the "cat" command to create the remote file.

echo 'Some Text' | ssh user@remotehost -T "cat > /remotefile.txt"

The -T disables pseudo-terminal allocation and stops you from getting the message,

Pseudo-terminal will not be allocated because stdin is not a terminal.

Related Question