Linux – How to Switch Between TTY and Xorg Session

linuxttyxorg

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?

Best Answer

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 ~/.xinit or ~/.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 startx.

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.).

Related Question