Ubuntu – What does “Ctrl + Alt + F12” do

shortcut-keys

I accidentally pressed Ctrl+Alt+F12 and my display turned to black… I then had to make a reboot.. What did it do to my system? Also what does Alt+ F8 to F10 do?

Best Answer

Pressing Ctrl+Alt+Fn (or just Alt+Fn when not in X11, the GUI) switches to the nth virtual console (ttyn).

Often we talk about a virtual console as a usable text console. So we often say there are six virtual consoles, accessible with Alt+F1 through Alt+F6 (holding down Ctrl too if you're in the GUI when you want to switch). And we often say that then, separately, is the GUI, which can be switched (back) to with Alt+F7.

But in fact, tty7, where the GUI typically runs, is a virtual console too. It's just not usable as a text console, because it doesn't have getty running for it. getty runs for tty1 through tty6 (by default). getty sets a virtual console up to be used like a terminal and runs login to prompt for a username and password.

You can see the getty commands that are running by filtering the output of ps:

ek@Kip:~$ ps ax | grep -v grep | grep getty
 1127 tty4     Ss+    0:00 /sbin/getty -8 38400 tty4
 1150 tty5     Ss+    0:00 /sbin/getty -8 38400 tty5
 1171 tty2     Ss+    0:00 /sbin/getty -8 38400 tty2
 1172 tty3     Ss+    0:00 /sbin/getty -8 38400 tty3
 1175 tty6     Ss+    0:00 /sbin/getty -8 38400 tty6
11231 tty1     Ss+    0:00 /sbin/getty -8 38400 tty1

Since tty7 is the first virtual console that is not set up to behave like a terminal (i.e., no getty is running for it), that's the one X11 (which provides the GUI) uses.

Virtual consoles higher than tty7 exist also. It's just that, ordinarily, they neither have getty running for them, nor do they have X11 using them. The first 12 virtual consoles are accessible with the key combinations described above using function keys (because a keyboard typically has only 12 numbered function keys). They are accessible even if nothing is happening on them.

Thus, when you press Ctrl+Alt+F12, you get a blank screen because you are now on tty12, which has nothing at all running on it.

As an interesting exercise, you might try running:

sudo /sbin/getty -8 38400 tty12

Then press Alt+F12 (or Ctrl+Alt+F12 if you're in the GUI rather than one of the first 6 virtual consoles).

This will bring you to tty12, which now has a login screen and is usable as a terminal.

(If you wanted to permanently create usable text-based consoles on higher-numbered virtual consoles, then you should configure init to run getty for them automatically. When getty is run manually as above, or even if you were to add that line to a startup script, you won't get the ability to login again after logging out on the virtual console, because getty won't automatically run again. Furthermore, there are some other problems running getty in that way for production use--for example, bash job control might not be available in your login shell, after you log in. If you want to make more virtual consoles usable as text-based terminal emulators, I recommend asking a separate question about that.)

Related Question