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?

share|improve this question
up vote 6 down vote accepted

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

share|improve this answer
    
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

You can switch tty as you have described by pressing:

  • Ctrl+Alt+F1 : (tty1)
  • Ctrl+Alt+F2 : (tty2)
  • Ctrl+Alt+F3 : (tty3)
  • Ctrl+Alt+F4 : (tty4)
  • Ctrl+Alt+F5 : (tty5)
  • Ctrl+Alt+F6 : (tty6)
  • Ctrl+Alt+F7 : (x is here when using ubuntu tty7)

You can also 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" to tty2-7, while RHEL 5 assigns dumb terminals to tty1-6, and x.org to tty7. Some x.org setups also make switching to any random dumb terminal 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 easily.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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