I have a serial port on a remote linux box which I can access over ssh.

I would like to create a file (not a real file, maybe a device file or unix domain socket?) which when written to writes to a remote serial port over ssh, and the reverse for reads.

I think it would be sufficient to have a command which creates a file, then makes the STDIN to the command accessible by reading from the file, and writes to the file would result in data output on the command's STDOUT stream. Then I could use it as such:

ssh user@host "cat /dev/ttyREAL" | <some_command> /dev/ttyFAKE | ssh user@host "tee /dev/ttyREAL"

Is there such a command, or am I going about it the wrong way?


3 Answers 3


Perhaps you can do something like this example using socat which creates a pseudo-tty and a symbolic link to it in ~/myserialline. When you open it socat runs ssh (in this example to localhost) where it runs socat to join stdin/stdout to a real serial device.

 socat PTY,link=$HOME/myserialline,raw,echo=0  EXEC:'ssh localhost socat - /dev/ttyS0'

You can test this from the (bash) shell, assuming you have such a serial device, with eg:

exec 3<>~/myserialline # open pty for read and write
cat -u <&3 &  # read from pty
echo hello >&3 # write to pty
  • This is more accurate than my answer.
    – user23673
    Jun 20, 2016 at 20:21

I'm not totally sure about the first part of the pipe you give as an example, but if you can somehow configure the program that writes to a serial port to use your fake serial port, you can simply write:

socat pty,link=$HOME/ttyFAKE,raw,echo=0 - | ssh user@host "tee /dev/ttyREAL"

socat will create the device for you.


I'm assuming you want this because you need to talk to a device in the other side of the serial port from the ssh connection, and that it's not a modem or some such (where you could use the network stack).

If the command that you want to write from can run a command and communicate to that using stdin and stdout, you can just use SSH itself, since SSH forwards stdin and stdout over the encrypted channel, as though the command were running locally. At that point, all you really need is a command that allows you to write to a serial port using stdin/stdout. The cu command does that; e.g., you could run ssh host cu -s 9600 -lttyS0.

If that doesn't do what you want, you're really going to have to provide more information...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .