Linux: Difference between /dev/console , /dev/tty and /dev/tty0
From the documentation:
/dev/tty Current TTY device /dev/console System console /dev/tty0 Current virtual console
In the good old days
/dev/consolewas System Administrator console. And TTYs were users' serial devices attached to a server. Now
/dev/tty0represent current display and usually are the same. You can override it for example by adding
grub.conf. After that your
/dev/tty0is a monitor and
An exercise to show the difference between
Switch to the 2nd console by pressing Ctrl+Alt+F2. Login as
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
ttyis the console where process starts, and
tty0is 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"`
one idiom for writing to files that require root privs is echo stuff | sudo tee /dev/tty0 >/dev/null;
Dammit. When Ī̲ wrote http://unix.stackexchange.com/a/229598/80483 , Ī̲ 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.)