104

I keep hearing about these things known as tty's.

  • what are they

  • how can I access them

  • what do they do?

1

5 Answers 5

106

tty is one of those funky Unix commands that prints the name of the terminal connected to standard input.

TTY's are text-only terminals commonly used as a way to get access to the computer to fix things, without actually logging into a possibly b0rked desktop.

Related: What is tty7 in the commandline?

By default, Ubuntu has 7 tty's.

  • On Ubuntu 17.10 and newer: It's GUI login screen on 1, GUI desktop on 2 and command lines on 3-7.
  • Up until Ubuntu 17.10: 1-6 are command line only and 7 runs your X session (your normal desktop).

To access them, use this keyboard shortcut:

Ctrl + Alt + F3 (or F1 until 17.10).

Changing F3 to F3-F6 to access the terminal that you want.

To get back to your GUI session (the normal desktop):

Ctrl + Alt + F2 (or F7 until 17.10).

4
  • 8
    Sir you have mentioned " to F1-F6 to access the terminal that you need" , how they are different and how to use them as per to need ,what kind of need is supported to which terminal. I dont know if it is the right place but your question and answer pointed it for me.
    – Sukupa91
    Nov 30, 2013 at 12:40
  • 4
    actually, if you are not in an X session, you can type just Alt+F7, you don't need the Ctrl.
    – fonini
    Dec 27, 2014 at 4:19
  • Since 17.10 aren't only 6 tty's? grep ACTIVE_CONSOLES /etc/default/console-setup Jul 12, 2022 at 23:26
  • 1
    I offer this answer, I aimed to represent this potentially confusing topic with enhanced clarity: askubuntu.com/a/1329549/1157519
    – Levente
    Jul 13, 2022 at 5:33
10

A tty, short for teletype and perhaps more commonly called a terminal, is a device which lets you interact with the system by sending and receiving data, such as commands and the output they produce.

There are many kind of ttys, but nowadays most ttys are implemented in software, such as the graphical consoles you can access with Ctrl+Alt+Fn, or terminal emulators such as Gnome terminal that run inside an X session.

There is also a tty command, which shows the device node of the terminal in which it is running (or prints "not a tty" if it is not running inside a terminal; yes, it is possible to run commands outside a terminal). For example:

firas@itsuki ~ % tty
/dev/pts/0
firas@itsuki ~ % ssh localhost tty
not a tty

When I am logged in and running a shell on the machine, the shell is normally running inside a terminal, namely here it is /dev/pts/0. However, when I run ssh host command to run a command on a remote host, the command is not run inside a terminal.

1
  • Is a terminal emulator a TTY or PTS?
    – Motivated
    Jan 5, 2019 at 17:57
4

You can change the displayed TTY by commmand line with chvt (requires sudo privileges), from SSH for example. Here is the relevant part of the manpage (man chvt):

CHVT(1)

NAME

chvt - change foreground virtual terminal

SYNOPSIS

chvt N

DESCRIPTION

The command chvt N makes /dev/ttyN the foreground terminal. (The corresponding screen is created if it did not exist yet. To get rid of unused VTs, use deallocvt) The key combination (Ctrl-)LeftAlt-FN (with N in the range 1-12) usually has a similar effect.

1
  • e.g. chvt 1 to switch to tty1 Nov 20, 2016 at 12:47
0

It changes your workspace: for example, you could have a text file open and change to tty2 then you might have a /ls command for reference. This is very helpful for an environment like Ubuntu Server.

This is the equivalent of having two tabs open in a GUI Environment.

In Ubuntu Server (16.04.3 LTS - for me) I can use ALT+F1-F6 or use ALT+LeftArrow to go back a number or ALT+RightArrow to go forwards a number.

You can see your tty by logging out from Ubuntu Server (run logout) and see up at the top Ubuntu 16.04.3 LTS ubuntu tty# that is standard, but may differ from version to version.

If your tty isn't shown on your login screen then you can run sudo nano /etc/issue and at the top, you can put in whatever you like but to add the tty you need to place \l. Place \n for the hostname.


Example:

/etc/issue

Ubuntu 16.04.3 LTS \n \l

would show

Ubuntu 16.04.3 LTS ubuntu tty#

Notes:

# refers to a number

1
  • I think you've made a good start at answering the "what do they do" part of the question though its still a bit above my head. There's something in your first sentence that I didn't follow. Could you clarify, for example, if I have a text file open in the normal GUI, then what can I achieve by accessing a tty that I can't do in the GUI?
    – Puffin
    Oct 4, 2018 at 21:29
0

AFAIK, on a decent functioning machine there is no difference (except there are colors in the desktop terminals, and you can minimize them and other little reasons they're easier)

HOWEVER, if you are trying to use an old laptop with < 4GB of RAM, or you messed up your debian install (still not sure, anyone stable on Dell inspiron 11-3162?); then the tty's will work when the desktop is lagging or malfunctioning or forgetting how to write a "d" for some reason: The ttys just work, and respond quickly. There is no press a button and wait 30 seconds to see it show up (if the desktop terminal even decides to behave at all) it just works.

ALSO just tested, nano still color codes in tty's, I'm sure vim or whatever you guys are into will as well.

THE other posts already showed you how to use them, it seemed you were confused as to why as well. This is the reason for my answering as I did; hope it helps.

EDIT also, it appears launching web pages from tty's is much more difficult than the simple one liner two string command from a terminal open in a gui

Tl;DR Gui terminals have more features and are easier in some ways but when the gui is buggy the tty's terminals work more quickly and efficiently.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .