hly19
hly19

Reputation: 81

What's the meaning of writing to /dev/ptmx

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.

Upvotes: 7

Views: 5450

Answers (1)

Florian Sc
Florian Sc

Reputation: 142

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.

Upvotes: 7

Related Questions