Linux: Difference between /dev/console , /dev/tty and /dev/tty0

  • On a Linux system, what is the difference between /dev/console, /dev/tty and /dev/tty0?

    What is their respective use and how do they compare?

    You may also be interested in this

  • dchirikov

    dchirikov Correct answer

    8 years ago

    From the documentation:

    /dev/tty        Current TTY device
    /dev/console    System console
    /dev/tty0       Current virtual console

    In the good old days /dev/console was System Administrator console. And TTYs were users' serial devices attached to a server. Now /dev/console and /dev/tty0 represent current display and usually are the same. You can override it for example by adding console=ttyS0 to grub.conf. After that your /dev/tty0 is a monitor and /dev/console is /dev/ttyS0.

    An exercise to show the difference between /dev/tty and /dev/tty0:

    Switch to the 2nd console by pressing Ctrl+Alt+F2. Login as root. Type sleep 5; echo tty0 > /dev/tty0. Press Enter and switch to the 3rd console by pressing Alt+F3. Now switch back to the 2nd console by pressing Alt+F2. Type sleep 5; echo tty > /dev/tty, press Enter and switch to the 3rd console.

    You can see that tty is the console where process starts, and tty0 is a always current console.

    nice exercise! Ubuntu locks root, so one way to reproduce this on Ubuntu is: `$ sudo sh -c "sleep5; echo tty0 > /dev/tty0"`

    @SFun28, I always used `sudo -i`, and voila - a root shell.

    one idiom for writing to files that require root privs is echo stuff | sudo tee /dev/tty0 >/dev/null;

    Dammit. When Ī̲ wrote , Ī̲ was unaware of *this* answer!

    @SFun28: if `sudo anycommand` works, then `sudo -i` to go root works too. There is no such thing as a Linux/BSD/Unix where you can’t go root. (Then it wouldn’t be Linux/BSD/Unix anymore.)

    What happens when you write to /dev/console? Does it has anything to do with the kernel console that can be viewed with `dmesg`?

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM