2

Was reading this article about automatically logging into a raspberry pi and they say to use this command:

1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1

After going through the manual I see that -f means no auth and that pi is the user, but what does

tty1 </dev/tty1 >/dev/tty1 2>&1

do?

I assume tty1 is the terminal to login into or something, but then the following arguments are confusing as well.

Why are there angle braces </dev/tty1 >? Are they doing some weird redirection?

I would really appreciate if someone could break it down. I'm not a fan of using commands I'm unfamiliar with.

  • These aren't angle braces - they're redirection symbols. You redirect stdin (<) from /dev/tty1 and redirect stdout (>) and stderror (2>) to /dev/tty1 – Dani_l Jan 14 '16 at 19:48
  • @Dani_l so what's the point of the very first tty1? Is it naming the terminal or something? – m0meni Jan 14 '16 at 19:51
  • 2
    I wonder why the article's author just didn't add the -a username option to getty, rather than replacing getty with login. – Mark Plotnick Jan 14 '16 at 20:09
1

Those are for input/output redirection. Command line programs display their results to standard output. By default, standard output directs its contents to the display. But when we need to redirect standard output to a file, the > character is used.

Commands can accept input from standard input. Normally we do input from the keyboard, With same logic as standard ouput it can be redirected. To redirect standard input from a file instead of the keyboard, the < character is used.

1

I'm unable to find what the first tty1 should do, since no manual page for login that I can find mentions any positional argument other than username, which is already specified. However, the rest of the line all deal with input output redirection, see (here)[http://www.tldp.org/LDP/abs/html/io-redirection.html] for nice short examples. Basically:

< /dev/tty1 redirects standard input to the login program from the device node tty1.

> /dev/tty1 redirects standard output to the same

2&>1 says to direct standard error (file descriptor nr 2) into standard output (file descriptor nr 1), which as such also sends it to tty1.

For some more info on the virtual terminals (ttys) see http://tldp.org/HOWTO/Text-Terminal-HOWTO-7.html

  • Okay I'm on mobile and can't figure out why no version of the brackets worked for the link, forgive me.. Will revisit tomorrow. – D.S Jan 14 '16 at 23:28

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.