My xorg session is on tty1 and if I want to issue a command from tty (because I cannot do it from xorg session for some reasons), I press Ctrl+Alt+F2, for example, and type a command. But I cannot start graphical applications from any tty except first since there is no xorg session in it. Then I am curious how can I switch to tty1 where xorg session is running and back to the session?
how can I switch to tty1 where xorg session is running and back to the session?
Because X is running on tty1, but not on tty2. A tty is a "virtual terminal", meaning it is supposed to represent an actual physical screen and keyboard, etc. The terminals are all on simultaneously, but since you only have enough hardware to interface with one at a time, that's what you get.
You can in fact run multiple X sessions on different ttys and switch between them. You need a valid
~/.Xclients first. If you don't, for illustration:
echo -e "#!/bin/sh\n mwm" > ~/.xinit chmod u+x ~/.xinit
Check first that
mwm exists by trying it from the command line. As long as it doesn't say "command not found" you're good. Now from tty2 try
If there isn't a display manager doing something totalitarian, you should get a plain black window with a big X mouse cursor. Left clicking should give a crude looking menu from which you can now "Quit"; but before that CtrlAltF1 will take you to the other X session on tty1 (and F2 gets you back, etc.).
You can switch tty as you have described by pressing:
- Ctrl+Alt+F1 : (tty1, X is here on Ubuntu 17.10+)
- Ctrl+Alt+F2 : (tty2)
- Ctrl+Alt+F3 : (tty3)
- Ctrl+Alt+F4 : (tty4)
- Ctrl+Alt+F5 : (tty5)
- Ctrl+Alt+F6 : (tty6)
- Ctrl+Alt+F7 : (tty7, X is here when using Ubuntu 17.04 and below)
You might also be able to use Alt+Left/Right
Note that different distros assign these differently. RHEL 6, for example, assigns the X server to tty1 and a "dumb terminal" / "console" to tty2-7, while RHEL 5 assigns consoles to tty1-6, and x.org to tty7. Some x.org setups also make switching to any random console more difficult; RHEL 5.5, for example, has a dedicated x.org key to switch to tty1, and from there you can get to tty2-6 more easily.
Alternatively, you can use the
chvt command -- for example,
sudo chvt 1 to switch to TTY1, and
sudo chvt 7 to switch back to the X session again. See here for more details.