What is TTY and PTY on Linux?

Linux TLDR
Last Updated:
Reading time: 5 minutes

If youโ€™ve been using Linux for a while, youโ€™ve probably heard the terms TTY and PTY. This article will explain what they are, how they affect Linux users, and their sweet little history.

TTY and PTY in Linux

So, letโ€™s start with their sweet little history to make things easier for non-technical readers.

The History Behind the Term โ€œTTYโ€

The story began in the late 1830s, when the first Teleprinter appeared.

Teletype teleprinters in use in England during World War II

The Teleprinter was an electronic device that let you send and receive text messages through the wire (either point-to-point or point-to-multipoint) as a substitute for Morse code.

Unlike Morse code, Teleprinters required just one trained operator to convey the message, making it easier to send messages across countries without a hitch (very effective for spies in WWII).

Donald Murray (inventor)

However, this device did not use a keyboard until Donald Murray introduced his first development of a typewriter-like keyboard in the late 1901s, which made punching a paper tape or transmitting data from the punched tape to the receiving printing machine much easier.

This development reduced the code combinations with the fewest punched holes to the most frequently used characters (the origin of the QWERTY keyboard), making it easier for operators to send a message.

Further, in 1908, a working Teleprinter was produced by the Morkrum Company as a field test; later, as this technology evolved, the Morkrum Company introduced the first commercial Teletypewriter (also known as TTY) system in 1910.

The difference between the Typewriter and Teletypewriter is that the Typewriter is used to write letters, while the Teletypewriter is a keyboard attached to a communication device (or a mainframe device that can accept input from a keyboard) to send typed messages.

With the Teletypewriter, the term โ€œTTYโ€ came into existence.

How is โ€œTTYโ€ Involved in Computing?

To understand its involvement in computing (or the Linux system), you should know that โ€œTTYโ€ refers to a communication device or any computing device that accepts keyboard input. So, letโ€™s continueโ€ฆ

The Teletypewriter came into existence ahead of its time, before the semiconductor transistors used to build microprocessors hit the market.

However, when the computer came into existence, they did not directly adopt the keyboard as an input method but instead went for punch cards.

Punch card

As the development of computing became more advanced, people started using Teletypewriters as a way to communicate with this device.

Teletype computer printer (1960s)

Gradually, more intelligent people became involved in the development of computing devices, replacing traditional mechanical TTY (introduced by the Morkrum Company) with virtual TTY (using electronics).

In parallel, a video terminal was also added to TTY because initially things were printed on paper instead of displaying on a screen. Thatโ€™s why you hear the terms โ€œprintโ€ for printing on paper and โ€œdisplayโ€ for displaying on a screen.

computer terminal

As video terminals (not Linux Terminal, the physical terminal above) got better, software that acted like them came out with more features and functions. This is where the term โ€œterminal emulatorsโ€ came from, which is now used for programs like GNOME Terminal, Konsole, Terminator, etc.

What is the difference between a video terminal and a terminal emulator?

The video terminal was a physical terminal (or video screen), also known as a TTY, that accepted input from the keyboard and displayed the output on screen. Terminal emulators are programs inside an operating system that take the input from the keyboard and display the output on the terminal screen.

Time for โ€œTTYโ€™sโ€ Entrance in the Linux World

Linux is also a computing device that accepts the keyboard as an input and displays the output on the screen (which properly falls under the TTY definition).

As development in Linux advanced, more features were added, like multiple tasking and a GUI desktop environment, so now you had to use PTY (pseudo-terminal, a child of TTY) using a terminal emulator.

So, whenever you launch a terminal emulator (like Gnome Terminal or Konsole), it comes with an attached PTY (which works under the shadow of a TTY) to help you communicate with the kernel.

However, the original (or parent) TTY is still accessible in Linux, in which the system console of the computer can be used to switch between multiple virtual consoles (or TTYs) to perform multitasking.

How to Access TTY in Linux

The TTY has two meanings: one is the serial ports of a computer to which the terminal was attached, and another is a virtual console (or TTY) that allows you to interact with your system.

In Linux, there are six virtual consoles or TTYs, and accessing them is pretty easy with a few key combinations, and you might already have interacted with them.

The following are keyboard shortcuts to enter on the TTY screen on most Linux distributions:

๐Ÿ“
The following key combination is system dependent; different systems might behave differently with the following shortcut, so itโ€™s better to check your OS configuration. However, Iโ€™ve been using Ubuntu as a prime example to cover the mass audience.
  • CTRL + ALT + F1 โ€“ Lockscreen
  • CTRL + ALT + F2 โ€“ Desktop Environment
  • CTRL + ALT + F3 โ€“ TTY3
  • CTRL + ALT + F4 โ€“ TTY4
  • CTRL + ALT + F5 โ€“ TTY5
  • CTRL + ALT + F6 โ€“ TTY6

As you can see, you have a total of six TTY screens, two of which are used to lock your screen or switch to a desktop environment, and four virtual consoles.

Why Are There 4 Virtual Consoles (or TTY Screens)?

The advantage of having multiple consoles is that you can easily multitask; for example, you can start TTY3 using the โ€œCTRL + ALT + F3โ€ key and update your system, and while itโ€™s updating, start TTY4 using the โ€œCTRL + ALT + F4โ€ key to continue your work while the system is being updated.

๐Ÿ’ก
You can easily switch between all the TTY screens using their keyboard shortcuts or the chvt command.
Using multiple virtual consoles

So, you get a complete command-line interface to communicate with your kernel on these virtual consoles (or TTYs).

What is the Advantage of Using Them?

The question of why you should have them is very legitimate for a regular or standard user, as you already have advanced systems with a beautiful desktop environment and can easily interact with consoles using the terminal emulator.

However, the TTY makes more sense when you accidentally remove your desktop environment; at that time, youโ€™re only left with the TTY screen, giving you a complete command-line interface to restore your system.

Another use case can be restoring your corrupted grub (or bootloader) or recovering from a frozen desktop environment.

Even if you are a system (or network) admin who just has to interact with a command line interface requiring no desktop environment, then TTY can be a good choice as it consumes less disk space and system resources, which indirectly improves your systemโ€™s performance.

What is the TTY Command in Linux?

In Linux, everything is represented as a file, even your hardware devices like hard disks, which are attached to a file located at the โ€œ/dev/โ€ path. Same, your terminal also represents a file whose path can be checked using the tty command.

$ tty

The above will print the file name of the terminal connected to standard input.

tty command

If you are connected through SSH, then you can use the who command to find the working tty.

$ who

Output:

Checking TTY through SSH

Even the commands running in your terminal utilize the TTY; that can be checked using the ps command.

$ ps

Output:

Checking the running process TTY

Thatโ€™s all a beginner should know about TTY.

However, if you want to dig deeper and understand this concept in depth, check out this article.

So, I hope this article helped you understand the concept of TTY in Linux. In case something was missed or something that should have been added was skipped, let us know in the comment section.

Join The Conversation

Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.