28

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?

12

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

  • What if I want to do it from ssh terminal? Doing startx is not possible from ssh terminal, isn't it? I need the ssh terminal to be in the same session with existing/running tty. – Oki Erie Rinaldi Aug 26 '17 at 1:52
21

You can switch tty as you have described by pressing:

  • Ctrl+Alt+F1 : (tty1 x is here on ubuntu 18.04+)
  • 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 14/16)

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.

related:

  • 1
    x is on tty1 on (current) ubuntu 18.04. – user8162 Sep 7 '18 at 9:54
18

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.