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/ttyrefers to the controlling terminal of the current process.
For example, a shell opened on a Linux virtual console may use a device such as:
/dev/tty2A shell opened in GNOME Terminal, inside tmux, through screen, or from script commonly uses a pseudoterminal slave such as:
/dev/pts/0The 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:
ttyOn an interactive shell attached to a pseudoterminal, sample output looks like this:
/dev/pts/4When standard input is not a terminal, the same command prints:
not a ttyTested 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:
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:
/dev/tty1 Linux virtual console
/dev/ttyS0 Serial terminal
/dev/pts/0 Pseudoterminal slave
/dev/tty Current process's controlling terminalCheck a virtual console
From a text console, run:
ttyA possible result is:
/dev/tty2Switching between virtual consoles may be possible with:
Ctrl+Alt+F2
Ctrl+Alt+F3The exact keys and available consoles vary by distribution, desktop environment, and system configuration.
Understand /dev/tty
List the device node:
ls -l /dev/ttySample 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:
ttyInside a pseudoterminal session:
/dev/pts/4To inspect session, process group, and terminal columns together, use the ps command:
ps -o pid,ppid,sid,pgid,tpgid,tty,stat,cmd -p $$Sample output on an interactive PTY:
PID PPID SID PGID TPGID TT STAT CMD
263840 263838 263840 263840 263840 pts/4 Ss bashThe TT field shows the controlling terminal. TPGID shows the foreground process group for that terminal.
You can also confirm the stdin device path directly:
readlink /proc/$$/fd/0Sample output:
/dev/pts/4What Are PTY and PTS?
A pseudoterminal is a bidirectional pair of virtual character devices:
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+Ccan 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:
/dev/ptmx PTY master multiplexer
/dev/pts/0 First active PTY slave
/dev/pts/1 Another active PTY slaveModern 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:
ttySample output:
/dev/pts/4In the second tab:
ttySample output:
/dev/pts/5Each 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:
ssh user@serverThen run:
ttyAn interactive login commonly reports:
/dev/pts/0For 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.
whoSample output showing SSH login records:
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:
ssh user@server ttySample output:
not a ttyssh -t user@server ttySample output:
/dev/pts/5The diagram below shows where the PTY is created in an SSH login:
tmux or screen
Terminal multiplexers such as tmux and screen allocate a separate PTY for each pane or window.
Start a tmux session:
tmuxThen run:
ttySample output:
/dev/pts/4Opening another tmux window or pane normally creates another PTY slave with a different /dev/pts/N number.
Pipeline or redirected input
Run:
echo test | ttySample output:
not a ttyThe 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:
Session
|
+-- Controlling terminal
| |
| `-- Current foreground process group
|
+-- Shell process group
|
`-- Command process groupsThe 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:
ps -o user,pid,ppid,sid,pgid,tpgid,tty,stat,cmdRead the columns like this:
SIDidentifies the session.PGIDidentifies a process group.TPGIDidentifies the foreground process group associated with the process's terminal.TTYshows 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:
mount | grep devptsSample output:
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,seclabel,gid=5,mode=620,ptmxmode=000)List active PTY slave nodes:
ls -l /dev/ptsSample 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 ptmxInspect one slave device:
stat /dev/pts/0Sample 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:
ls -l /dev/tty1 /dev/ttyS0 /dev/console /dev/ptmxSample 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/ttyS0Why Programs Need a PTY
Many programs behave differently when attached to a terminal.
Common PTY users include:
- Terminal emulators
- SSH interactive sessions
tmuxandscreenscriptandscriptreplayexpectsudosessions 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:
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:
script -q -c 'test -t 0 && echo "stdin is a terminal"' /dev/nullSample output:
stdin is a terminalCheck standard output the same way:
test -t 1 && echo "stdout is a terminal"Or:
[[ -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:
docker exec container commanddocker exec -it container bash-ikeeps standard input open.-tallocates 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:
ttyShow the current terminal line settings, including control characters and echo flags:
stty -aWhen 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:
ps -o pid,ppid,sid,pgid,tpgid,tty,stat,cmdShow which device backs the shell's standard input:
readlink /proc/$$/fd/0List every open file descriptor for the current shell, including sockets and terminal devices:
ls -l /proc/$$/fd/List recorded login sessions and their TTY devices:
whoShow logged-in users, idle time, and the command each TTY is running:
wRestore a broken terminal to a usable default state:
resetSummary
- TTY is the general Linux terminal abstraction.
/dev/ttyNusually represents a virtual console./dev/ttyS*and/dev/ttyUSB*represent serial terminals./dev/ttyrefers to the current process's controlling terminal.- A PTY consists of a master and slave endpoint.
/dev/pts/Nis 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
- tty(1)
- tty(4) —
/dev/ttyand controlling terminals - pts(4) —
/dev/ptmxand/dev/ptsdevices - pty(7)
- termios(3)
- ssh(1)

