TTY vs PTY vs PTS in Linux: /dev/tty and /dev/pts Explained

Understand TTY, PTY and PTS in Linux, including /dev/tty, /dev/pts, controlling terminals, terminal emulators, SSH, tmux, and practical commands.

Published

Updated

Read time 11 min read

Reviewed byDeepak Prasad

Linux TTY and PTY master-slave architecture with dev tty and dev pts devices

TTY, PTY, and PTS are related Linux terminal concepts, but they do not represent the same thing.

  • TTY is the general Linux terminal interface.
  • PTY is a software-created pseudoterminal consisting of a master and slave.
  • PTS normally refers to the slave side of a PTY, exposed as /dev/pts/N.
  • /dev/tty refers to the controlling terminal of the current process.

For example, a shell opened on a Linux virtual console may use a device such as:

output
/dev/tty2

A shell opened in GNOME Terminal, inside tmux, through screen, or from script commonly uses a pseudoterminal slave such as:

output
/dev/pts/0

The number after /dev/pts/ changes with each tab, SSH session, or pane. Run tty on your current shell to print the device path connected to standard input:

bash
tty

On an interactive shell attached to a pseudoterminal, sample output looks like this:

output
/dev/pts/4

When standard input is not a terminal, the same command prints:

output
not a tty

Tested on: Rocky Linux 10.2; kernel 6.12.0-211.28.1.el10_2.x86_64.


TTY vs PTY vs PTS at a Glance

Term Meaning Common device or endpoint Typical use
TTY Terminal interface /dev/tty1, /dev/ttyS0 Virtual consoles and serial terminals
PTY Pseudoterminal pair Master plus slave Software-created interactive terminals
PTY master Controller endpoint used by the terminal emulator, SSH daemon, or multiplexer Usually an open file descriptor from /dev/ptmx Terminal emulator, SSH daemon, tmux
PTS PTY slave /dev/pts/0 Shell or terminal-aware application
/dev/tty Current controlling terminal Resolves through the calling process Reading from or writing to the current terminal

A TTY is the general terminal abstraction. A PTY is a virtual TTY pair created by software, and /dev/pts/N is normally the slave endpoint used by the shell.


Understand Terminal, Shell, TTY, and Terminal Emulator

These four terms are often mixed together:

Term Purpose
Terminal Interface through which text input and output are exchanged
Shell Command interpreter such as Bash or Zsh
Terminal emulator Graphical or text application that displays terminal output and accepts keyboard input
TTY driver Kernel terminal interface providing terminal behavior

The diagram below shows the usual relationship in a graphical desktop session:

Terminal emulator connected to a shell through PTY master and PTS slave devices

Clarify the roles like this:

  • Bash is a shell, not a terminal.
  • GNOME Terminal, Konsole, and xterm are terminal emulators.
  • The terminal emulator normally controls the PTY master.
  • The shell sees the PTY slave as its terminal.
  • Closing the terminal emulator usually closes the PTY and affects the attached shell.

What Is a TTY in Linux?

TTY comes from teletypewriter. In modern Linux it means the kernel terminal layer that presents a character device with line discipline, job control, and signal delivery.

Depending on the device, a TTY may represent a virtual console, serial terminal, controlling terminal, or the slave side of a pseudoterminal.

Device Meaning
/dev/tty1 to /dev/ttyN Linux virtual consoles
/dev/ttyS0 Hardware or emulated serial terminal
/dev/ttyUSB0 USB serial adapter
/dev/console System console device
/dev/tty Calling process's controlling terminal
/dev/pts/N Pseudoterminal slave

Examples:

text
/dev/tty1       Linux virtual console
/dev/ttyS0      Serial terminal
/dev/pts/0      Pseudoterminal slave
/dev/tty        Current process's controlling terminal

Check a virtual console

From a text console, run:

bash
tty

A possible result is:

output
/dev/tty2

Switching between virtual consoles may be possible with:

text
Ctrl+Alt+F2
Ctrl+Alt+F3

The exact keys and available consoles vary by distribution, desktop environment, and system configuration.

Understand /dev/tty

List the device node:

bash
ls -l /dev/tty

Sample output:

output
crw-rw-rw-. 1 root tty 5, 0 Jul 14 01:21 /dev/tty

/dev/tty is not tied permanently to one numbered terminal. It refers to the controlling terminal of whichever process opens it. The kernel documents /dev/tty as a synonym for the calling process's controlling terminal, when one exists.

Compare the device reported by tty with the file descriptor behind standard input:

bash
tty

Inside a pseudoterminal session:

output
/dev/pts/4

To inspect session, process group, and terminal columns together, use the ps command:

bash
ps -o pid,ppid,sid,pgid,tpgid,tty,stat,cmd -p $$

Sample output on an interactive PTY:

output
PID    PPID     SID    PGID   TPGID TT       STAT CMD
 263840  263838  263840  263840  263840 pts/4    Ss   bash

The TT field shows the controlling terminal. TPGID shows the foreground process group for that terminal.

You can also confirm the stdin device path directly:

bash
readlink /proc/$$/fd/0

Sample output:

output
/dev/pts/4

What Are PTY and PTS?

A pseudoterminal is a bidirectional pair of virtual character devices:

text
PTY master <---- bidirectional channel ----> PTY slave
  • Data written to the master appears as input on the slave.
  • Output written to the slave can be read from the master.
  • The slave provides terminal behavior expected by shells and interactive programs.
  • Control characters such as Ctrl+C can generate signals for the foreground process group.

PTY and PTS are not the same label:

  • PTY: The complete pseudoterminal mechanism, including master and slave.
  • PTY master: Used by a terminal emulator, SSH daemon, tmux, or another program.
  • PTS: The pseudoterminal slave presented to the shell, usually as /dev/pts/N.

Linux exposes the devices like this:

text
/dev/ptmx       PTY master multiplexer
/dev/pts/0      First active PTY slave
/dev/pts/1      Another active PTY slave

Modern Linux programs open /dev/ptmx to allocate a UNIX 98 PTY and obtain a corresponding slave under /dev/pts. Opening /dev/ptmx returns a master file descriptor and creates an associated slave under /dev/pts; data written on either side is delivered through the other endpoint.


See TTY and PTY in Real Linux Sessions

Graphical terminal emulator

Open two terminal tabs and run tty in each one.

In the first tab:

bash
tty

Sample output:

output
/dev/pts/4

In the second tab:

bash
tty

Sample output:

output
/dev/pts/5

Each terminal tab normally receives a different /dev/pts/N slave. The who command displays recorded login sessions, such as virtual-console and SSH logins, but it may not list every graphical terminal tab.

SSH session

Connect with the ssh command:

bash
ssh user@server

Then run:

bash
tty

An interactive login commonly reports:

output
/dev/pts/0

For an interactive login, SSH normally requests a PTY when the local SSH client is itself attached to a terminal. OpenSSH documents that -T disables allocation, -t forces it, and repeated -t options can force allocation even when the client has no local TTY.

After connecting, list recorded SSH login sessions with who. To inspect broader connection state, see list and check active SSH connections in Linux.

bash
who

Sample output showing SSH login records:

output
root     pts/0        2026-07-13 23:14 (10.0.2.2)
root     pts/1        2026-07-14 01:38 (10.0.2.2)

Compare a noninteractive remote command with a forced PTY:

bash
ssh user@server tty

Sample output:

output
not a tty
bash
ssh -t user@server tty

Sample output:

output
/dev/pts/5

The diagram below shows where the PTY is created in an SSH login:

SSH client and sshd allocating a pseudoterminal for a remote shell

tmux or screen

Terminal multiplexers such as tmux and screen allocate a separate PTY for each pane or window.

Start a tmux session:

bash
tmux

Then run:

bash
tty

Sample output:

output
/dev/pts/4

Opening another tmux window or pane normally creates another PTY slave with a different /dev/pts/N number.

Pipeline or redirected input

Run:

bash
echo test | tty

Sample output:

output
not a tty

The tty command reports the terminal connected to standard input. When standard input is a pipe or file rather than a terminal, it reports that it is not a TTY.


Understand Controlling Terminals and Job Control

A Linux session may have one controlling terminal, shared by the processes in that session. At any moment, one process group is the terminal's foreground group, while the remaining process groups run in the background.

A typical interactive session looks like this:

text
Session
  |
  +-- Controlling terminal
  |       |
  |       `-- Current foreground process group
  |
  +-- Shell process group
  |
  `-- Command process groups

The terminal tracks the foreground process group. That enables actions such as:

Key Typical terminal action
Ctrl+C Generate SIGINT
Ctrl+Z Generate SIGTSTP
Ctrl+\ Generate SIGQUIT
Ctrl+D Send the terminal's EOF control character; on an empty input line, the next read returns end-of-file

Signal generation for Ctrl+C, Ctrl+Z, and Ctrl+\ depends on the terminal's termios settings such as ISIG.

Inspect session, process group, and terminal fields with ps:

bash
ps -o user,pid,ppid,sid,pgid,tpgid,tty,stat,cmd

Read the columns like this:

  • SID identifies the session.
  • PGID identifies a process group.
  • TPGID identifies the foreground process group associated with the process's terminal.
  • TTY shows the controlling terminal.
  • A daemon or noninteractive process may display ? because it has no controlling terminal.

Compare /dev/tty, /dev/ttyN, /dev/pts/N, and /dev/ptmx

These paths are frequently confused:

Path Meaning Created or managed by
/dev/tty Current process's controlling terminal Kernel TTY layer
/dev/tty1 Virtual console number 1 Kernel virtual console and login service
/dev/ttyS0 Serial terminal port Serial driver
/dev/ptmx Allocates a new PTY master PTY subsystem
/dev/pts/0 Slave endpoint of an allocated PTY devpts filesystem
/dev/console System console Kernel console subsystem

Show the devpts mount:

bash
mount | grep devpts

Sample output:

output
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)

List active PTY slave nodes:

bash
ls -l /dev/pts

Sample output:

output
total 0
crw--w----. 1 root tty  136, 0 Jul 14 23:22 0
crw--w----. 1 root tty  136, 1 Jul 14 22:35 1
crw--w----. 1 root tty  136, 2 Jul 14 12:26 2
c---------. 1 root root   5, 2 Jul 13 22:48 ptmx

Inspect one slave device:

bash
stat /dev/pts/0

Sample output:

output
File: /dev/pts/0
  Size: 0         	Blocks: 0          IO Block: 1024   character special file
Device: 0,25	Inode: 3           Links: 1     Device type: 136,0
Access: (0620/crw--w----)  Uid: (    0/    root)   Gid: (    5/     tty)

/dev/pts is a virtual filesystem containing active PTY slave device nodes. Entries appear and disappear as PTYs are allocated and released.

Compare other TTY-related device nodes:

bash
ls -l /dev/tty1 /dev/ttyS0 /dev/console /dev/ptmx

Sample output:

output
crw--w----. 1 root tty     5,  1 Jul 13 22:48 /dev/console
crw-rw-rw-. 1 root tty     5,  2 Jul 14 22:35 /dev/ptmx
crw--w----. 1 gdm  tty     4,  1 Jul 13 22:48 /dev/tty1
crw-rw----. 1 root dialout 4, 64 Jul 13 22:48 /dev/ttyS0

Why Programs Need a PTY

Many programs behave differently when attached to a terminal.

Common PTY users include:

  • Terminal emulators
  • SSH interactive sessions
  • tmux and screen
  • script and scriptreplay
  • expect
  • sudo sessions when its policy or I/O logging uses a PTY — password prompts and terminal requirements are covered in the sudo command reference
  • Interactive container sessions
  • Test and automation tools that must emulate a user terminal

Check whether standard input is a terminal:

bash
test -t 0 && echo "stdin is a terminal"

When standard input is not a terminal, the command prints nothing.

Allocate a pseudoterminal with script and run the same test:

bash
script -q -c 'test -t 0 && echo "stdin is a terminal"' /dev/null

Sample output:

output
stdin is a terminal

Check standard output the same way:

bash
test -t 1 && echo "stdout is a terminal"

Or:

bash
[[ -t 1 ]] && echo "interactive output"

Terminal-aware programs may change:

  • Colour output
  • Progress bars
  • Line buffering
  • Password prompts
  • Full-screen interfaces
  • Signal handling
  • Input editing

PTY in containers

Compare:

bash
docker exec container command
bash
docker exec -it container bash
  • -i keeps standard input open.
  • -t allocates a pseudo-TTY.
  • Interactive shells normally need both.
  • Do not allocate a TTY for pipelines carrying binary data unless required.

The same -i and -t pattern applies to Podman and other OCI runtimes.


Troubleshoot TTY and PTY Problems

Symptom Likely cause Recommended check
tty prints not a tty Standard input is a pipe, file, or noninteractive channel Run test -t 0
SSH command has no terminal Noninteractive SSH command did not allocate a PTY Use ssh -t only when required
Automation hangs on a password prompt Program expects an interactive terminal Use noninteractive credentials or a controlled PTY tool
Colours disappear in redirected output Program detected that stdout is not a terminal Check test -t 1 and application colour options
sudo says a terminal is required Password prompt or policy requires a terminal Run interactively or use an approved noninteractive design
Terminal output is garbled Terminal modes were changed Run stty sane or reset
Backspace or Enter behaves incorrectly Incorrect terminal settings Check stty -a
Ctrl+C does not stop the expected command Foreground process group or signal handling differs Inspect PID, PGID, TPGID, and TTY
Process shows TTY ? Process has no controlling terminal Expected for daemons and many background jobs
SSH session behaves differently with -T No PTY was allocated Compare ssh -T and ssh -t
tmux panes show different PTS numbers Each pane has its own PTY Expected behavior
/dev/pts/N disappears The owning PTY session ended Check active shells and terminal emulators

Useful commands:

Print the terminal device connected to standard input:

bash
tty

Show the current terminal line settings, including control characters and echo flags:

bash
stty -a

When standard input is not a terminal, stty may report Inappropriate ioctl for device.

List processes with session, process group, foreground group, and controlling terminal columns:

bash
ps -o pid,ppid,sid,pgid,tpgid,tty,stat,cmd

Show which device backs the shell's standard input:

bash
readlink /proc/$$/fd/0

List every open file descriptor for the current shell, including sockets and terminal devices:

bash
ls -l /proc/$$/fd/

List recorded login sessions and their TTY devices:

bash
who

Show logged-in users, idle time, and the command each TTY is running:

bash
w

Restore a broken terminal to a usable default state:

bash
reset

Summary

  • TTY is the general Linux terminal abstraction.
  • /dev/ttyN usually represents a virtual console.
  • /dev/ttyS* and /dev/ttyUSB* represent serial terminals.
  • /dev/tty refers to the current process's controlling terminal.
  • A PTY consists of a master and slave endpoint.
  • /dev/pts/N is normally the PTY slave seen by the shell.
  • Graphical terminal emulators, SSH, tmux, screen, and containers commonly allocate PTYs.
  • Shells and terminals are separate components.
  • PTYs provide terminal behavior, job control, signals, and interactive input to software-created sessions.

References


Frequently Asked Questions

1. What is the difference between TTY, PTY, and PTS?

TTY is the general Linux terminal interface. PTY is a software-created pseudoterminal pair with a master and slave. PTS normally refers to the slave side exposed as /dev/pts/N.

2. What does the tty command show?

The tty command prints the pathname of the terminal device connected to standard input, such as /dev/pts/0 or /dev/tty2. It prints not a tty when standard input is not a terminal.

3. What is /dev/tty in Linux?

/dev/tty is an alias for the controlling terminal of the calling process when that process has one. It is not permanently bound to /dev/tty1 or any other numbered console.

4. What is the difference between /dev/tty1 and /dev/tty?

/dev/tty1 is virtual console number 1. /dev/tty refers to whichever terminal currently controls the process that opens it.

5. What is /dev/pts/0?

/dev/pts/0 is usually the slave endpoint of an allocated pseudoterminal. Shells in graphical terminal emulators, SSH sessions, tmux panes, and similar tools commonly use /dev/pts/N paths.

6. Is an SSH session a TTY or PTY?

An interactive SSH login normally uses a pseudoterminal. The remote shell sees the PTY slave, often /dev/pts/N, while sshd controls the PTY master.

7. Why does tty print not a tty?

Standard input is not connected to a terminal device. Common causes include pipes, file redirection, cron jobs, and noninteractive SSH commands that do not allocate a PTY.

8. What do ssh -t and ssh -T do?

ssh -t forces pseudo-terminal allocation even when stdin is not a terminal. ssh -T disables PTY allocation, which is appropriate for many noninteractive remote commands.

9. Does a graphical terminal use a PTY?

Yes. Terminal emulators such as GNOME Terminal, Konsole, and xterm normally open a PTY master and attach the shell to the PTY slave under /dev/pts.

10. Is Bash a terminal or a shell?

Bash is a shell. It runs inside a terminal device provided by a virtual console or a pseudoterminal slave.

11. Why does each tmux pane have a different /dev/pts number?

tmux allocates a separate pseudoterminal for each pane or window. Each allocation receives its own /dev/pts/N slave device.

12. What is /dev/ptmx?

/dev/ptmx is the UNIX 98 pseudoterminal multiplexer. Programs open it to allocate a new PTY master and obtain a corresponding slave under /dev/pts.

13. Why do some commands behave differently without a TTY?

Many programs test whether stdin or stdout is a terminal before enabling colour, progress bars, password prompts, or full-screen interfaces.

14. What does the TTY question mark in ps output mean?

A question mark means the process has no controlling terminal. Daemons, background jobs, and many service processes commonly show TTY ?.

15. What is a controlling terminal?

A Linux session may have one controlling terminal shared by processes in that session. The terminal tracks one foreground process group at a time for job control and signal delivery.
Deepak Prasad

R&D Engineer

Founder of GoLinuxCloud with more than 15 years of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive …