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 nobody@ > /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 nobody@
  • 1
    If you just want to disable the password prompt, use -o PasswordAuthentication=no, and consider the -n option. – muru Dec 6 '14 at 17:07

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.