Ubuntu telnet server - password stream

I am trying to create a Telnet server using Python on Ubuntu 12.04. To be able to execute commands as another user, I need to use the su command, which then asks for the password. Now I know that the invitation was sent to the STDERR stream, but I have no idea which stream I should send the password to. If I try to send it via STDIN, I get an error message: su: must be run from a terminal . How can I continue?

+4
source share
1 answer

If you really want to use the system su program, you will need to create a pair of terminals, see man 7 pty , in python, that call pty.openpty , which returns you a couple of file descriptors, one for you and one for su. Then you have fork, in the child process change stdin / out / err to slave fd and exec su. In the parent process, you send data and receive data from master fd. The Linux kernel connects them together.

Alternatively, could you emulate su instead?

+1
source

Source: https://habr.com/ru/post/1437655/


All Articles