添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

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.

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 4, 2022 at 14:50

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.