How does ssh prompt for a password when all input and output is redirected?

I don’t actually need to run the command below, and I am aware of ssh keys if I did want to log in without typing a password. I would just like to know how ssh seems to circumvent my file redirection.

Running the following command, ssh prompts me for a password:

ssh <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d5bbbab7bab1ac95e4ece7fbe4e3edfbe4fbe4e0e4">[email protected]</a> > /dev/null 2> /dev/null < /dev/null

How does this work? stdin, stdout, and stderr are all redirected, but ssh still manages to print a prompt on my screen and read what I type. I tried adding the ssh arguments -t -t and -T (not both at once), to enable or disable pseudo-tty allocation, but it made no difference.

I also tried closing all input and output this way, although I don’t know if I typed it correctly. Still, ssh prompts for a password:

(exec 0<&- 1<&- 2<&- 0>&- 1>&- 2>&-; ssh <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0d63626f6269744d3c343f233c3b35233c233c383c">[email protected]</a>)

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

From OpenSSH readpassphrase.c, line 75:

    /*
     * Read and write to /dev/tty if available.  If not, read from
     * stdin and write to stderr unless a tty is required.
     */

The program reads and writes the TTY directly hence it’s not possible to disable direct input by just closing the standard input and output pipes. You have to tell the SSH client to use a supplied password or do as suggested by @muru.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x