Text terminals on Linux today: emulators, serial consoles, tmux
Hardware text terminals are rare now, but the terminal model is everywhere in Linux: every terminal window, SSH session and text console is a "tty" device with a type in TERM that programs look up in the terminfo database. This page explains those pieces, how to rescue a garbled terminal, how to set up a serial console, and how tmux and screen keep sessions alive.
The classic version of this HOWTO, written for real terminals on serial lines, is kept by the LDP at tldp.org. Commands below apply to current Debian, Ubuntu, Fedora, RHEL-family, Arch and openSUSE systems as of November 2026.
Three kinds of tty
Run tty to see which device your shell is talking to.
- Pseudo-terminals,
/dev/pts/0,/dev/pts/1and so on, are created on demand for terminal windows, SSH logins and tmux panes. A program such as your terminal emulator orsshdholds the "master" side and your shell gets the other side. - Virtual consoles,
/dev/tty1to/dev/tty6by default, are the full-screen text logins the kernel draws itself. Switch to them with Ctrl+Alt+F3 from a desktop. The keyboard and console HOWTO covers their keymaps and fonts. - Serial ports,
/dev/ttyS0(the first built-in UART, COM1),/dev/ttyUSB0(USB-to-serial adapters) and/dev/ttyACM0(USB modem-class devices such as many microcontroller boards). These are where real terminals used to connect, and where servers, routers and embedded boards still offer a console.
Terminal emulators
A terminal emulator is a graphical program that pretends to be a hardware terminal. Desktops ship their own (GNOME and KDE each have one, KDE's is Konsole), and there are many independent ones, such as xterm, Alacritty, foot, kitty and WezTerm. They all understand the same core of escape sequences inherited from the DEC VT100 and xterm, then add extras such as true color, clickable links or image display. Each one sets TERM for the programs it starts, usually to xterm-256color or to its own name.
TERM and terminfo
Programs such as less, vim, htop and Bash's line editor do not hard-code escape sequences. They read $TERM and look up that terminal type in the terminfo database to learn how to clear the screen, move the cursor or set colors.
echo "$TERM" # e.g. xterm-256color, linux, tmux-256color
tput colors # 256 for xterm-256color, 8 for linux, -1 for vt220
infocmp | head -5 # show the compiled entry for your TERM
infocmp -x tmux-256color > /dev/null && echo "tmux-256color is installed"
Compiled entries live under /usr/share/terminfo (also /etc/terminfo, and ~/.terminfo for your own). On Debian and Ubuntu, ncurses-base has the common entries and ncurses-term adds hundreds more.
"unknown terminal type" over SSH
When you SSH from a newer emulator to an older server, the server may not know your TERM. You will see 'xterm-kitty': unknown terminal type. from clear, or tput: unknown terminal "xterm-kitty", and editors behave oddly. Two fixes:
# Quick: claim a type every server knows, for this session only
TERM=xterm-256color ssh server.example.com
# Proper: copy your entry to the server (it is compiled into ~/.terminfo there)
infocmp -x | ssh server.example.com -- tic -x -
tic reads the description from standard input when given -, and -x keeps the extended capabilities modern emulators use. Some distributions package entries for popular emulators; on Debian, for example, kitty-terminfo.
Fixing a garbled terminal
After cat-ing a binary file or a program crashing, the terminal may show line-drawing symbols, stop echoing what you type, or ignore Enter. Type these blind if needed, and end each with Ctrl+J if Enter does not work:
reset # re-initialize the terminal and its settings
stty sane # restore sensible line settings (echo, line editing, signals)
tput sgr0 # just turn off colors and bold
stty -a shows the current line settings, including which keys send interrupt (intr = ^C), end-of-file (eof = ^D) and erase (erase = ^?). stty size prints rows and columns. If Backspace prints ^H, run stty erase ^H (type the caret and H literally), or fix the emulator's Backspace setting.
Setting up a serial console
A serial console gives you a login and boot messages over a cable or a virtual machine's serial port, even when the network is down. You need three parts: kernel messages, a login prompt, and (optionally) the boot loader menu.
1. Kernel messages
Add console= parameters to the kernel command line. The kernel sends messages to every listed console, and the last one becomes /dev/console:
console=tty0 console=ttyS0,115200n8
115200n8 means 115,200 bit/s, no parity, 8 data bits. On Debian and Ubuntu, add it to GRUB_CMDLINE_LINUX in /etc/default/grub and run sudo update-grub. On Fedora and the RHEL family, use sudo grubby --update-kernel=ALL --args="console=tty0 console=ttyS0,115200n8", which updates all current and future boot entries. The kernel command-line HOWTO covers other boot loaders.
2. A login prompt
With console=ttyS0 on the command line, systemd's systemd-getty-generator starts serial-getty@ttyS0.service automatically. Without it, or for a second port, enable it yourself:
sudo systemctl enable --now serial-getty@ttyS0.service
systemctl status serial-getty@ttyS0.service
The unit runs agetty, which prints the login prompt and hands over to login. Its default command line tries 115200, 57600, 38400 and 9600 bit/s, keeping the current speed if it works. To set the TERM value used on that port (systemd 254 and later), add a kernel parameter such as systemd.tty.term.ttyS0=xterm-256color; otherwise export TERM=… after logging in.
3. GRUB on the serial line (optional)
# /etc/default/grub
GRUB_TERMINAL_INPUT="console serial"
GRUB_TERMINAL_OUTPUT="gfxterm serial"
GRUB_SERIAL_COMMAND="serial --unit=0 --speed=115200"
Regenerate the configuration afterwards: sudo update-grub on Debian and Ubuntu, sudo grub2-mkconfig -o /boot/grub2/grub.cfg on Fedora and RHEL. Use console instead of gfxterm if your setup has no graphical terminal.
Connecting from another machine
sudo usermod -aG dialout "$USER" # Debian, Ubuntu, Fedora; Arch uses the uucp group
# log out and back in, then:
picocom -b 115200 /dev/ttyUSB0 # exit with Ctrl+A Ctrl+X
screen /dev/ttyUSB0 115200 # exit with Ctrl+A k
minicom -D /dev/ttyUSB0 -b 115200 # exit with Ctrl+A X
For a virtual machine, virsh console NAME attaches to its serial port. If you see garbage, the speeds do not match. If you see nothing, press Enter, check the cable (a null-modem cable is needed between two computers), and confirm the getty is running.
Magic SysRq over serial. On a standard PC serial port, sending a BREAK followed within 5 seconds by a command key triggers SysRq functions, which can help on a hung server. In picocom, Ctrl+A Ctrl+\ sends a BREAK.
tmux and screen: sessions that survive
A terminal multiplexer runs your shells inside a server process, so they keep running when you close the window or your SSH connection drops. It also splits one terminal into windows and panes.
| Task | tmux | GNU screen |
|---|---|---|
| Start a named session | tmux new -s work | screen -S work |
| Detach (leave running) | Ctrl+B d | Ctrl+A d |
| List sessions | tmux ls | screen -ls |
| Reattach | tmux attach -t work | screen -r work |
| New window | Ctrl+B c | Ctrl+A c |
| Next / previous window | Ctrl+B n / p | Ctrl+A n / p |
| Split side by side / top and bottom | Ctrl+B % / " | Ctrl+A | / S |
| Scroll back (copy mode) | Ctrl+B [ | Ctrl+A [ or Ctrl+A Esc |
tmux reads ~/.tmux.conf or ~/.config/tmux/tmux.conf. A minimal configuration:
# ~/.config/tmux/tmux.conf
set -g default-terminal "tmux-256color" # TERM inside tmux; must be screen, tmux or a variant
set -g mouse on # click to select panes, wheel to scroll
set -g history-limit 50000 # lines of scrollback per pane
set -sg escape-time 10 # faster Esc in vim
Reload it inside tmux with tmux source-file ~/.config/tmux/tmux.conf. Inside tmux, TERM is tmux-256color (or screen), not your outer terminal's type; this is correct. If the server lacks the tmux-256color entry, use screen-256color. Start tmux on the remote host, not your laptop, so the session survives a dropped connection.
Sources
- Linux Serial Console, kernel.org documentation
- Linux Magic System Request Key Hacks, kernel.org documentation
- agetty(8) manual page, man7.org
- systemd-getty-generator(8), man7.org
- kernel-command-line(7) (systemd.tty.term.*), man7.org
- terminfo(5), tic(1M), infocmp(1M) and tput(1), man7.org
- stty(1) manual page, man7.org
- tmux(1) manual page, man7.org and tmux wiki
- screen(1) manual page, man7.org
- picocom(1) and minicom(1), Debian manpages
- virsh manual (console command), libvirt
- Working with the serial console, ArchWiki
- GRUB 2 (grubby usage), Fedora Project Wiki
- Working with the GRUB 2 boot loader, Fedora Docs