1

On Ubuntu, /dev/tty7 is the virtual console for desktop GUI.

Is the only way to access /dev/tty7 to use chvt 7 or Ctrl+Alt+F7?

Besides that, is /dev/tty7 not directly accessible to Ubuntu users, but indirectly via other emulations of terminals built upon /dev/tty7? For example, typing this in a xterm window doesn't give any output:

echo hello > /dev/tty7

but this will

echo hee > /dev/pts/n
slava
  • 173
Tim
  • 101,790
  • 1
    You don't usually see the text terminal on tty7 since it has a display server running. If you kill the display server you should see an output. – Torin Nov 30 '18 at 13:54
  • Since 17.10 (?) tty1 is a login screen, tty2 is the desktop GUI and 3-6 are text consoles. Don't know what tty7 is for. Previously 1-6 were text and 7 was the GUI. – PerlDuck Nov 30 '18 at 13:57
  • Why would emulated terminals be “built upon /dev/tty7”? – Stephen Kitt Nov 30 '18 at 13:59
  • @StephenKitt look at how /dev/pts/2 is built upon /dev/tty7 in "the chain of interaction" at https://unix.stackexchange.com/a/229598/674. I am not sure what you think is correct. – Tim Nov 30 '18 at 14:05
  • That “chain of interactions” is rather inaccurate. – Stephen Kitt Nov 30 '18 at 14:20
  • @StephenKitt do you mind pointing out what is inaccurate and what it should be? – Tim Nov 30 '18 at 14:24
  • https://unix.stackexchange.com/a/405689/86440 – Stephen Kitt Nov 30 '18 at 14:29
  • @StephenKitt do you mean X server communicates with the physical text terminal not indirectly via virtual console /dev/tty7 but directly? – Tim Nov 30 '18 at 14:39
  • 1
    X doesn’t communicate with a text terminal, but yes, I mean X doesn’t interact with the user via /dev/tty7 (or any other terminal device) but by managing the input and output devices directly. – Stephen Kitt Nov 30 '18 at 14:55
  • @StephenKitt (1) Is "a text terminal" not an "input and output device"? (2) Since I am running Ubuntu on /dev/tty7, I guess /dev/tty7must be involved somehow between my terminal emulator window and my physical terminal (my display, keyboard, touchpad)? – Tim Nov 30 '18 at 15:04
  • (1) It’s rather difficult to output graphics on a text terminal. By input and output devices I meant the graphics device, keyboard, mouse etc. (2) Your guess is wrong. Also, you’re not running Ubuntu on /dev/tty7; you’re running X or Wayland on the seventh virtual console. /dev/tty7’s involvement is mostly limited to ensuring that nothing else can grab the seventh virtual console; input and output don’t go through it. – Stephen Kitt Nov 30 '18 at 15:15
  • @StephenKitt Thanks. Sorry I know it is already long."/dev/tty7’s involvement is mostly limited to ensuring that nothing else can grab the seventh virtual console". How does a device file ensure that? – Tim Nov 30 '18 at 15:28
  • The device file is used to set the session group’s controlling terminal (with the TIOCSCTTY ioctl). The kernel only allows one session group to be controlled by a given terminal (although it’s possible to steal a controlling terminal). – Stephen Kitt Nov 30 '18 at 16:19
  • @StephenKitt Thanks. What does "running X or Wayland on the seventh virtual console" mean? I guess it means something different from "ensuring that nothing else can grab the seventh virtual console" and "input and output don’t go through it"? – Tim Nov 30 '18 at 23:16
  • You wrote “I am running Ubuntu on /dev/tty7”, to which I replied “you’re not running Ubuntu on /dev/tty7; you’re running X or Wayland on the seventh virtual console”. That’s all. – Stephen Kitt Dec 03 '18 at 14:16

1 Answers1

0

In Ubuntu releases before 17.10 Ubuntu has 6 virtual consoles tty1-tty6 which are accessed by the keyboard combinations Ctrl+Alt+F1 to Ctrl+Alt+F6. To access the GUI from any virtual console press the keyboard combination Ctrl+Alt+F7.

Starting with Ubuntu 17.10, which allowed the user to select either Xorg or Wayland when logging in, the virtual consoles are accessed by the keyboard combinations Ctrl+Alt+F3 to Ctrl+Alt+F6. To access the GUI from any virtual console press the keyboard combination Ctrl+Alt+F2.

/dev/tty is the controlling tty of the current process, for any process that actually opens this special file. It isn't necessarily a virtual console. For example running the command echo hello > /dev/tty in the terminal returns hello, but running sudo echo hello > /dev/tty0 to sudo echo hello > /dev/tty7 returns an error message similar to bash: /dev/tty0: Permission denied

getty, short for "get tty", is a Unix program running on a host computer that manages physical or virtual terminals (TTYs). When it detects a connection, it prompts for a username and runs the 'login' program to authenticate the user.Wikipedia  On most Debian systems tty7 is used by the X Window System, so if you want to add more getty's go ahead, but skip tty7 if you run X.

karel
  • 2,030
  • 1
    I think the reason sudo echo hello > /dev/tty0 fails is not what you think it is. Also, Debian 9 and later behave like Ubuntu, with the login session on VC 1, and GUIs on VCs 2 and up. – Stephen Kitt Nov 30 '18 at 16:22
  • I remember to run echo hello > /dev/tty0, you have to first sudo su. sudo isn't enough, although I don't know why and also want to know why. – Tim Nov 30 '18 at 16:27
  • 1
    See this https://unix.stackexchange.com/a/60649/674 "Login as root" – Tim Nov 30 '18 at 16:38
  • Just sudo isn't enough because the redirection is done by the shell before starting sudo, so it's done with the user's permissions only. – stolenmoment Dec 01 '18 at 14:18