Working with TTY sessions
Table of Contents
- Introduction
- Acknowledgements
- Caution
- About TTY sessions
- Working With TTY sessions
- Printable Cheat Sheet
- Appendix
- Obligatory Happy Ending
Introduction
- Impatient? Don’t want to read a bunch of stuff? Get right to it!
- You may run into a situation where you need to accomplish a task and someone helpful suggests that you open a TTY session to get the job done. Usually this person will tell you how to open such a session and accomplish your task, but not how to get back out of the session when you’re finished.
- This guide hopes to shed some light on what these sessions are and how to access, use, and get back out of them.
- The use of “Ubuntu” in this guide includes its derivatives (flavors).
Caution
The default TTY session numbers below are for Ubuntu and its derivatives. If you use a different operating system, please check its release notes or check with its support team for the structure of its TTY sessions, compare them with the information in this page, and make adjustments to the steps below before proceeding.
Acknowledgements
I would like to thank John F. Morse for explaining TTY sessions to me in the first place, and Frank Pirrone for contributing the “What is the history of TTY?” section to this document.
About TTY sessions
- What does TTY mean?
- TTY means the use of a keyboard, mouse, or other hardware to interact with an application on a computer.
- What does session mean?
- A session is the period of time spent interacting with an application on a computer.
- What are TTY sessions?
-
- A TTY session is the environment you are in while interacting with your computer. To put it more graphically, when you open a TTY session, you’re running what can basically be understood as a copy of Ubuntu.
- Ubuntu installs 7 sessions onto your computer by default.
- All 7 sessions are loaded every time you boot up Ubuntu.
- Each session is independent of the other sessions.
- Sessions opened by the same user can interact with each other. For example, a file created in one session will be visible and accessible in other sessions the user has open.
- Each session has a login, so different users can be logged into the same computer under different sessions at the same time.
- Each session has an address by which it is known to Ubuntu
- Ubuntu reserves one of these addresses for the default session.
- You use the default session every time you boot into Ubuntu.
- You are free to use the other 6 sessions at any time.
- All of the sessions work the same way. You can use any or all of them.
- See the Appendix for the history of TTY.
- What are TTY sessions really called?
- A more technically correct name for these sessions would be “virtual console” or “virtual terminal,” but since they’re more frequently referred to as “multiple TTY session,” and since their addresses are represented by device special files /dev/tty1 through /dev/tty7, this document uses “multiple TTY session” or “TTY session” when discussing them.
- Why do I need multiple TTY sessions?
-
- If you run into trouble and need to accomplish a task, and a helpful person suggests using a TTY session to accomplish the task, you’ll need to know how to work with multiple TTY sessions.
- If another user wishes to log in to the computer you’re currently using and you don’t wish to stop what you’re doing or log out, you can use multiple TTY sessions. Up to 7 different users can be logged into the same computer at the same time.
- If you’re experiencing a minor lockup, but still have use of the keyboard, you might be able to use another TTY session to “come in from behind” and debug and/or fix the lockup.
- Perhaps you have tasks that you regularly perform, like recording music, editing videos, creating web pages, etc. If you’d like to define sessions which load up the applications needed for those tasks in separate sessions, multiple TTY sessions would be very useful. Such use is outside the scope of this document, but you can do further research on how it’s done by typing man xinit or man startx in a terminal window.
Working With TTY sessions
Choose a session
Before you begin, you must choose a session to open.
- The sessions you can choose from:
- <Ctrl><Alt><F1>
- <Ctrl><Alt><F2>
- <Ctrl><Alt><F3>
- <Ctrl><Alt><F4>
- <Ctrl><Alt><F5>
- <Ctrl><Alt><F6>
- The sessions you cannot choose from:
- The address of the default session in Ubuntu is always <Ctrl><Alt><F7>. Since this is used by Ubuntu, you may not open a new session at this address.
- If a session is currently open at any of the 6 addresses listed above, you cannot open a new session at that address until that session is closed.
Open a session
Each session will open in terminal mode. You can use it as is or load the GUI. This section includes instructions for both.
Open a TTY terminal session
-
Open a new TTY session by pressing these three keys at the same time:
<Ctrl><Alt><F#>
Replace # with the session number you’d like to open.
- Enter your user name and password.
- Use the terminal session just as you would any other terminal.
Open a TTY GUI session
-
Open a new TTY session by pressing these three keys at the same time:
<Ctrl><Alt><F#>
Replace # with the session number you’d like to open.
- Enter your user name and password.
-
Start the GUI by typing this command:
startx
Note that in Ubuntu and its derivatives, startx — :0 is reserved for use by the system for the default GUI session.
- Press the Enter key.
- Use the GUI as you normally would.
Manage sessions
-
Keep an eye on things:
-
Check what’s happening in which session. In a GUI TTY session, open a terminal window to enter this command. If you’re in a terminal TTY session, you can enter the command at the prompt. Type:
w
-
Check what’s happening in which session. In a GUI TTY session, open a terminal window to enter this command. If you’re in a terminal TTY session, you can enter the command at the prompt. Type:
-
Switch from the new session to the default session:
-
Press these three keys at the same time:
<Ctrl><Alt><F7>
-
Press these three keys at the same time:
-
Switch from the default session to the new session:
-
Replace # in the following command with the session number you have open. Press these three keys at the same time:
<Ctrl><Alt><F#>
-
Replace # in the following command with the session number you have open. Press these three keys at the same time:
-
Switch to other sessions
- Switch to other sessions by pressing the three keys that correspond to each session’s address. You can switch back and forth between sessions as much as you like.
Close a session
Close a TTY terminal session
-
Log out of the session by typing this command:
exit
- Press the Enter key.
-
Return to your default session by pressing these three keys at the same time:
<Ctrl><Alt><F7>
Close a TTY GUI session
- Use your GUI menu to log out of the GUI normally. This will bring you back to the terminal prompt for your TTY session.
-
Log out of the TTY session by typing this command:
exit
- Press the Enter key.
-
Return to your default session by pressing these three keys at the same time:
<Ctrl><Alt><F7>
Printable Cheat Sheet
Here is a cheat sheet to print out for quick reference.
Appendix
What is the history of TTY?
Obligatory Happy Ending
And they all lived happily ever after. The end.
Hey good stuff…keep up the good work! :)
Comment by Bill Bartmann — September 9, 2009 @ 1:17 pm
Hey,
I want to know is there any way in which i can open the tty-1 in my GUI window itself. Because when ever i switch between the terminals, my GUI will look very nasty. All the color resolution every thing will be a mess. I can’t change it. To make it proper i need to restart my system. I don’t want to do that every time i switch to get a better view of my GUI. Please let me know if i can open a tty-x terminal in my GUI window itself.
thanks in advance.
Comment by yogi9119 — November 1, 2009 @ 12:30 am
When you say, “color resolution every thing will be a mess,” do you mean that the GUI colors are affected in the default TTY session when you open other TTY sessions, or that the GUI colors are affected in the other TTY sessions you open, or both? Can you provide more detail on what happens when you open TTY sessions?
Since each session is independent of any other sessions, it shouldn’t be possible to open one session from within another session, but you should be able to access specific sessions via the network. The remote-tty package looks promising. You could also do a Google search on remote tty access to look for other alternatives and/or instructions on how best to go about doing something like this.
What does “get a better view of my GUI” mean? A different tool might be better for the job, depending on what you’re trying to do.
As far as more detail, when you open another TTY session, you are opening a completely separate copy of Ubuntu. There are seven sessions, but only one of them is active by default. I suppose if you were to open more than one as GUI sessions, you could be using too many of your system’s resources, which could result in graphical glitches. Do you see the same graphical problems if you don’t load a GUI in the additional TTY sessions?
Comment by mostlylinux — November 1, 2009 @ 1:13 pm
Thanks for ur reply,
When you say, “color resolution every thing will be a mess,” do you mean that the GUI colors are affected in the default TTY session when you open other TTY sessions, or that the GUI colors are affected in the other TTY sessions you open, or both? Can you provide more detail on what happens when you open TTY sessions?
As soon as i boot my system,by default it will take me to GUI window, when i login in that window or without loging in to the GUI; If i open the other terminal tty-1 or any other; when i get back to GUI window all the color every thing look very hazy. “As if some one has dipped a painting in water”. I hope you got wat i’m trying to say :). And this happens only in the GUI, all other TTY sessions will be perfectly fine.
What does “get a better view of my GUI” mean? A different tool might be better for the job, depending on what you’re trying to do.
I mean if i’m able to get back my original GUI as it loads when i boot my system is more than sufficient for me, when i switch b/n the tty-x and GUI terminal.
With Respect to the link you provided for remote-tty;
all of them talk about connecting to different machines through Telenet or SSH. But i don’t have another machine to connect, i don’t want to connect to other machine either. I want to open tty-x session of my own ubuntu which is running in my pc in one of the terminal, in my present GUI window itself and operate with in that.
Please do ask me if you need any further clarifications.
Thank you once again.!! :)
Comment by yogi9119 — November 1, 2009 @ 11:48 pm
This definitely sounds like a system resource problem. It’s possible that you need to update the video driver so that it can properly display graphics. Are you using the default video driver that comes with Ubuntu, or did you install a proprietary driver? If you haven’t installed a proprietary driver, you might want to try that.
As far as connecting to TTY sessions via telnet or SSH, you could do this from a virtual machine that has a different IP from that of the host machine, but if system resources are the problem, that would only make matters worse. Sadly, this seems to be the only way to open a TTY session within another session.
Can you tell me what you need the TTY sessions for? You might be able to use workspaces instead. Hopefully this will work for you. (:
Comment by mostlylinux — November 2, 2009 @ 6:12 pm
yeah may be the video driver is the problem. I have not installed any video driver separatly. I’m using the built in driver which came in Ubuntu. I have a 512Mb graphics card installed in my lappy. I think i need to install a driver for it to work properly.
i’m having windows vista home editon in one of my partetion, which has come wit builtin drivers n all. If i install the new driver here. Is it going to affect my driver settings in windows? Because earlier i had problem with my wifi driver in linux. so i installed wifi driver, which was causing some problems in windows vista. Later i uninstalled that driver in ubuntu to make it work properly in windows. So i just want to know is it going to affect any settings in windows.
“Can you tell me what you need the TTY sessions for?”
Hmm
I’m learning Linux Device Driver programming. If i run the code in GUI all the display messages will be in some log files. I’m facing little bit difficulty in tracing the errors which occours during run time. When I compile the same code in TTY i’ll get the messages displayed on the console directly. It will make my life easier when i try to debug it. But due to bad resolution problem i’m not able to swtich b/n the GUI and TTY. So it will be very helpful if i get my TTY in my current GUI itself. Also I can’t use my mouse in TTY which is a kind of hindrance to me. So I need somthing which will solve my problem :).
Different workspace will not solve my problem as again it will be in GUI and all the messages will be loged to log files. I need somthing like a PUTTY window which we use it in Windows. Which will satisfies all my criteria. I know PUTTY is by default there in Linux. But i’m talking about some application similar to that which can be opened in the GUI window itself and all the messages will be displayed on it.
As usual please let me know if you need any further clarifications. :)
Thanks for your reply.
Comment by yogi9119 — November 3, 2009 @ 12:08 am
I’m not sure how many laptops come with video cards that can use proprietary drivers. I know my HP laptop can’t, but it’s a few years old. Installing a Linux video driver will not affect Windows.
I took a look at the PUTTY website and it seems it uses a terminal emulator. As far as I know, that’s any terminal that’s running inside a GUI. Have you tried the terminal that comes with Ubuntu? It’s in the GNOME menu in the Accessories section.
There are many terminal emulators for Linux. One I think you might especially like is Screen. A couple of tutorials for it are available here and here. Descriptions of some other terminal emulators can be found here and here. I’m not sure if all of those are to be found in the package manager, but if you type terminal into the package manager’s search box, you’ll be busy for a while checking them all out. (:
Comment by mostlylinux — November 3, 2009 @ 1:25 am
I want to kill all these session so I use the pkill command, now what happened that after giving this command I logout and when again I am trying to ssh to remote host I get connection refused error:
I have two questions:
can we logout the users based on tty session…………….?
now what to do to make remote host function normally………?
Below is the screen output:
***********************************************************************************************
wcs1:/ # who
emt pts/0 2012-01-25 13:31
root pts/1 2012-01-02 09:22 (:1.0)
root pts/2 2012-01-02 09:22 (:1)
root pts/4 2012-01-29 15:39 (:2.0)
root pts/5 2012-01-29 15:39 (:2)
root pts/6 2012-02-07 20:25 (2.91.167.148)
root pts/8 2012-02-01 11:33 (:3)
root pts/9 2012-02-04 14:12 (:5.0)
root pts/7 2012-02-01 11:33 (:3.0)
root pts/10 2012-02-04 12:34 (:4.0)
root pts/11 2012-02-04 12:34 (:4)
root pts/12 2012-02-04 14:09 (:5)
root pts/13 2012-02-07 20:36 (:6.0)
root pts/14 2012-02-07 20:36 (:6)
wcs1:/ # tty
/dev/pts/6
wcs1:/ # pkill -9 -u emt
wcs1:/ # who
root pts/1 2012-01-02 09:22 (:1.0)
root pts/2 2012-01-02 09:22 (:1)
root pts/4 2012-01-29 15:39 (:2.0)
root pts/5 2012-01-29 15:39 (:2)
root pts/6 2012-02-07 20:25 (2.91.167.148)
root pts/8 2012-02-01 11:33 (:3)
root pts/9 2012-02-04 14:12 (:5.0)
root pts/7 2012-02-01 11:33 (:3.0)
root pts/10 2012-02-04 12:34 (:4.0)
root pts/11 2012-02-04 12:34 (:4)
root pts/12 2012-02-04 14:09 (:5)
root pts/13 2012-02-07 20:36 (:6.0)
root pts/14 2012-02-07 20:36 (:6)
wcs1:/ # pkill -9 -u root
Connection to xxx.xxx.xxx.xx closed by remote host.
Connection to xxx.xxx.xxx.xx closed.
[rashid@localhost ~]$ ssh root@xxx.xxx.xxx.xx
ssh: connect to host xxx.xxx.xxx.xx port 22: Connection refused
[rashid@localhost ~]$ ssh root@xxx.xxx.xxx.xx
ssh: connect to host xxx.xxx.xxx.xx port 22: Connection refused
[rashid@localhost ~]$ ping xxx.xxx.xxx.xx
PING xxx.xxx.xxx.xx (xxx.xxx.xxx.xx) 56(84) bytes of data.
64 bytes from xxx.xxx.xxx.xx: icmp_req=1 ttl=55 time=15.4 ms
64 bytes from xxx.xxx.xxx.xx: icmp_req=2 ttl=55 time=36.9 ms
^C
— xxx.xxx.xxx.xx ping statistics —
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 15.470/26.221/36.973/10.752 ms
[rashid@localhost ~]$ clear
***********************************************************
Kindly advise.
Regards,
Rashid
Comment by Rashid — February 7, 2012 @ 2:33 pm
I have no experience with SSH, but I took a look around and found this page and this page, both of which made for some fascinating reading.
One thing that seems to be important is that you need to have administrative power to issue these commands, so if you’re using Ubuntu or one of its derivatives, you want to use sudo before the command.
Here are a few things to try:
All three of these commands should still leave the TTY sessions working and ready for use by someone else. I think the only reason you had trouble logging back on was because you pkilled root, so it was probably mad at you. :)
Comment by mostlylinux — February 7, 2012 @ 3:50 pm
very very bad service of mostlylinux
Comment by gotak nath — February 9, 2012 @ 7:22 am
I’m so sorry! Is there something I can do better?
Comment by mostlylinux — February 9, 2012 @ 3:05 pm
The way “TTY GUI session” is written, taken in the context of following the previous section, people are likely to get the impression that a third or fourth GUI session might be started in same manner as “startx — :1”, which won’t work once a second GUI session has been started. Some earlier mention that the default session is on :0 should help, but the section really needs more detail spelled out for any who would like more than 2 concurrent GUI sessions.
Comment by Felix Miata — July 10, 2014 @ 11:40 pm
Done! Thanks for pointing it out! Instead of suggesting that they number them sequentially based on how many GUI sessions there are, I figured I’d suggest that they use the same number as the session number. It’s probably easier to remember – even for advanced users. (:
Comment by mostlylinux — July 11, 2014 @ 12:24 am
Traditionally, tty7 has been the location for :0, but not all distros or releases have adhered to it, and more recently fewer do. Some distros have taken to putting :0 on tty1, tty5 or tty8, while X is usually configured for only :0-:2 or :0-:3, leaving your tty# mnemonic failing if started from tty4, tty5, tty6 and maybe tty3 too, for those few interested in so many concurrent sessions. It used to be the general rule with :0 on tty7 that :1 would be on tty8, :2 on tty9, etc, but that rule has pretty well loosened too. Assuming another release or distro will work the way it does on whichever you’ve tested on is doomed to failure for no small proportion of readers actually interested in multiple concurrent X sessions.
In recent years it’s been common for some popular DEs to enable switching to another session directly without closing an existing session. This is probably the better way to initiate additional sessions for most users, but for some this won’t work either. Individual users’ X sessions can be preconfigured to use a unique xorg.conf or startup script utilizing xrandr commands to configure multiple screen layouts, panning, scaling, resolution and more, but I don’t think any of the DE’s support this, meaning startx is still required for support of such custom configurations. However, there is such a thing as customization via the DE itself, e.g. in KDE.
Xorg is sophisticated and complex, so one must be careful about describing “expected” behavior. Too little information can hurt somewhat like too much can.
Comment by Felix Miata — July 11, 2014 @ 1:36 am
Thanks for the explanation! I really appreciate the time you’ve taken to write up these detailed comments. In the hope that I’ve properly understood them, I’ve removed the inadvisable part (about numbering the startx sessions with the same number as the TTY sessions) from the page and put instructions to number the startx sessions sequentially instead. I’ve also added a caution section near the top of the page and inserted a comment or two in the body of the page.
I realize that there are probably very sophisticated things one can do with these sessions. My goal isn’t to discover and describe how to do them all, but rather to give sort of a basic, simple presentation of TTY sessions so visitors can get an idea of what they are and then decide for themselves if they want to do further research on their own. Your comments will probably start up quite a few very interesting adventures. (:
Comment by mostlylinux — July 11, 2014 @ 11:02 am
Thanks for this post, it’s a nice intro to get started!
Suited me perfectly :D
Comment by steffington — October 9, 2014 @ 4:37 am
Good work.. Congratz ..
Comment by codingDelight — December 5, 2014 @ 1:41 am
Thanks! That’s very kind of you. (:
Comment by mostlylinux — December 5, 2014 @ 10:34 am
Thanks for the info. Normally some Linux Distro OSes have 7 tty already active. But when we list in /dev, there are more than 60 tty in my case. Why there are too many? Are they necessary to be there or could I reduce the number of them?
Comment by fajarichwannoor — February 6, 2015 @ 9:26 pm
It looks like they’re necessary and you probably shouldn’t remove any of them: http://stackoverflow.com/questions/8514735/what-is-special-about-dev-tty
I did ls -l tty in my /dev directory and there were 98 of them, and it looks like they were all created when I booted the machine this afternoon. (:
Comment by mostlylinux — February 7, 2015 @ 12:00 am
okay then… it’s been 11 days since your answer, could you list again how many tty in your /dev ? Is it still the same 98? Thank you.
Comment by fajarichwannoor — February 17, 2015 @ 12:15 pm
Yes, I still have 98 today. Do you still have the same number you had on the 7th?
Comment by mostlylinux — February 17, 2015 @ 6:58 pm
[…] https://mostlylinux.wordpress.com/troubleshooting/ttysessions/ […]
Pingback by Ubuntu:Why so many Virtual consoles? – Ubuntu Linux Questions — October 20, 2015 @ 5:41 am
Extremely useful and helpful – thank you. I plan to visit this site often – But for what it’s worth the font you’re using here is a little tough to read for these old eyes – haha. Maybe it’s just me – but thanks for this site! Ben
Comment by Anonymous — January 23, 2017 @ 3:00 pm
I’m glad you like the blog, and I’m sorry it’s tough on your eyes. This was the most readable theme I was able to find. I sometimes check if they’ve come up with new ones that will work. If you know of one, feel free to let me know and I’ll test it.
Comment by mostlylinux — January 26, 2017 @ 12:39 pm