1

I'm reading the source code of sshfs. And I find out that when trying to give the password to ssh, it write the password to /dev/ptmx.

write(sshfs.ptyfd, sshfs.password, strlen(sshfs.password));

I know it's the master side of pseudo-terminal, but I don't really understand meaning of writing to it. I tried to echo something to /dev/ptmx but nothing happened. Maybe I'm not fully understand the mechanism of pts and ptmx.

user438383
  • 5,716
  • 8
  • 28
  • 43
hly19
  • 21
  • 4

1 Answers1

3

The idea of ptmx is that your application creates a virtual console for communication with other applications or with the operating system.

By opening ptmx, an application gets a filed descriptor (basically a number) which gives your application the possibility to communicate over a virtual terminal with other applications.

These other applications can open your terminal by opening /dev/pts/12345 for example.

Echo'ing to /dev/ptmx makes no sense because the only function of /dev/ptmx is to provide your application with a file descriptor of a newly created /dev/pts/ device which can be used by echo.

Florian Sc
  • 102
  • 6
  • I don't really get it: When two applications open /dev/ptmx, do they open the same file? – hly19 May 03 '22 at 10:08
  • 3
    Actually not.. It's like a shop for virtual consoles to communicate with other applications... You open it and thereby create a order => You receive a file descriptor that references to a new created serial console. ptmx is just a provider for virtual serial consoles - not an actual serial console. – Florian Sc May 04 '22 at 14:50