Detailed Explanation of TTY and PTS Terminals in Kirin Linux

This article is an original work by Teacher Liu from Yunbei Education. Please respect intellectual property rights; when forwarding, please indicate the source. No plagiarism, adaptations, or unauthorized reposting are accepted.

In the Linux operating system, TTY (Teletypewriter) and PTS (Pseudo Terminal Slave) are two different types of terminals. They each have different uses and characteristics, which are crucial for understanding the user interface of Linux and how to perform operations such as remote login.

1. tty (Teletype)
  • Definition and History

tty is an abstraction of physical or virtual terminals, originating from early teletypes. In modern Linux, each physical terminal or virtual console (such as the interfaces switched by Ctrl+Alt+F1~F6) corresponds to a tty device.

  • Device Files

Device files are located at /dev/ttyN (e.g., /dev/tty1), or virtual terminals like /dev/ttyS0 (serial terminals).

  • Usage Scenarios
  • Physical console (directly connected keyboard and monitor).
  • Virtual terminals switched by Ctrl+Alt+Fn.
  • Serial terminals (e.g., debugging embedded devices).
  • Characteristics
  • Direct interaction with the kernel, no need for network protocols.
  • Strict permission control (e.g., /etc/securetty can restrict root login to tty devices).
2. pts (Pseudo-Terminal Slave)
  • Definition and Use

pts is the slave side of a pseudo-terminal, used to simulate terminal behavior. It usually appears in pairs with ptmx (the master device of the pseudo-terminal), created by terminal emulators (like SSH, graphical terminal).

  • Device Files

Dynamic device files are located at /dev/pts/N (e.g., /dev/pts/0), with each session assigned a unique number.

  • Usage Scenarios
  • SSH remote login.
  • Terminal emulators in graphical interfaces (like GNOME Terminal, Konsole).
  • Session multiplexing with screen or tmux.
  • Characteristics
  • Data forwarding through the master-slave device pair (ptmx and pts).
  • Supports network transmission (e.g., SSH encrypted communication).
  • User permissions are more flexible (depending on the user of the initiating process).
3. Core Differences

Feature

tty

pts

Device Type

Physical terminal or virtual console

Pseudo-terminal (network/simulated terminal)

Device Path

/dev/ttyN or /dev/ttySN

/dev/pts/N

Creation Method

Pre-allocated at system startup

Created dynamically (on demand)

Dependency

Direct connection or virtual console

Requires master device (ptmx) to cooperate

Typical Applications

Local console, serial devices

SSH, graphical terminals, terminal multiplexing

4. Viewing Current Terminal Type
• Command Example
# View current terminal device file path
$ tty
/dev/pts/0  # If it is a pseudo-terminal, it shows pts; if it is a physical terminal, it shows ttyN
# View the terminal associated with the process
$ ps -p $$   # View terminal information of the current Shell
5. Workflow of Pseudo-Terminals (PTS)

1. Master-Slave Device Creation

When a user logs in via SSH or a graphical terminal, the terminal emulator (like sshd) creates a pair of pseudo-terminals:

  • Master Device (ptmx): Controlled by the terminal emulator, responsible for receiving user input.
  • Slave Device (pts): Associated with the user’s Shell process, receiving content forwarded from the master device.

2. Data Flow

User Input → Master Device (ptmx) → Slave Device (pts) → Shell Process

Shell Output → Slave Device (pts) → Master Device (ptmx) → Terminal Display

6. Common Questions
Why does the SSH session show as pts?

SSH simulates terminal behavior through pseudo-terminals, so the session is associated with /dev/pts/N.

How to restrict user login through pts?

Edit the /etc/securetty file (only list allowed tty devices, excluding pts).

Differences in permissions between tty and pts

tty devices typically belong to root:tty, while pts devices belong to the user who started them.

Conclusion

tty: Directly associated with hardware or virtual consoles, suitable for local operations.

pts: Simulated through pseudo-terminals, used in remote or graphical environments, offering greater flexibility.

Understanding the differences between the two helps in troubleshooting terminal permissions, session management issues (e.g., SSH configuration or /dev device permission errors).

If you want to learn more related study materials (technical articles and videos), you can search for ‘Yunbei Education’ on WeChat public account or Bilibili to get them for free.

Detailed Explanation of TTY and PTS Terminals in Kirin Linux

Leave a Comment