1

Is there a way that one computer can share the a device in the /dev/ directory with another computer, and the other computer can interact with it is if it is local? Something analogous to an SSH tunnel?

A camera for example, or a serial connection to an arduino, or even the computer's /dev/random?

  • Thank you. I don't know why I didn't find that. But now there are some fantastic answers on this question too, so I guess it's best not to delete this question. – Alex028502 Jan 14 '22 at 19:38
  • I wish there were some way to merge them – Alex028502 Jan 14 '22 at 19:39
  • like jira tickets – Alex028502 Jan 14 '22 at 19:39
  • @Alex028502 This idea of merging questions is accomplished on Stack Exchange by closing questions as duplicates of another. That appears to be what is happening right now based on Artem's comment and the close votes that are building up. If you agree with the duplicate, you can accept it right away, or the U&L community will review it and vote to close it as a duplicate (or leave it open). If there's a reason to keep it open & separate, please [edit] your question to make the distinction. Thank you! – Jeff Schaller Jan 14 '22 at 21:20

2 Answers2

2
  1. Mounting a block device

No, this is not possible via ssh - you would need to mount the device on the server, then may use sshfs to mount the remote location to a local one.

  1. Interacting

Yes, sending and receiving data is possible by using ssh with remote commands:

ssh user@server 'cat /dev/random'

will give you the output from the server's random device. The same way you may send data:

ssh user@server 'cat - >/dev/null' <<<"Hello"

Is this "like local" - no. but depending on your plans it might be sufficient.

FelixJN
  • 13,566
2

In short, no. The ways you interact with device nodes are "richer" than what you can do with actual files, and without the kernel on the remote machine having access to your local process memory (which it doesn't, over network), that's not possible.

Not to mention a lot of things you'd want to work with simply have unreasonably high bandwidth requirements (e.g. a high-quality camera in a raw mode), low latency requirements (any USB bulk device that expects something to happen on the computer side within a specified time) or other functional aspects that make operation over the network on a raw device level impossible.

For that reasons, for some device classes, where it is possible to divide what has to be done close to the device and what can be done remotely, there's other approaches: For example, printers can be quite nicely shared via network using CUPS, sound devices using pipewire, jackd or other daemons, video devices using VLC, storage devices either as file systems using NFS, CIFS, … or as block devices (e.g. in Ceph).

Your serial port would be quite easy to abstract - you do the setting up (mostly: opening, setting the baudrate) on the machine where it is, and then just use a minimal network daemon that reads and writes to it.

In fact, that's quite a common pattern, having an UART port somehow addressable over network, in industry automation. Under linux, the socat programm can do things like that.