Unknown terminal type or "Error opening terminal" when you use tmux, screen or SSH
Why a host rejects TERM names like tmux-256color, how to copy the terminfo entry to your home folder with infocmp and tic, and how to change TERM.
unknown terminal type
Error opening terminal: tmux-256color.
These messages mean the host looked up your TERM name in its terminfo database and did not find it. A common case is a name that comes from tmux. For the general idea of TERM see TERM and terminfo.
How the name gets there
Inside tmux, TERM is set by the tmux option default-terminal. The tmux manual says it must be set to screen, tmux or a derivative of them. So inside tmux you see names such as screen-256color or tmux-256color.
When you connect to another host with SSH from inside tmux, the name is sent along. The OpenSSH manuals say TERM is always sent when a pseudo-terminal is requested. The new host may not have an entry with that name, and its programs stop with the message above.
Check the name first:
echo $TERM
Fix 1: use a name the host has, for this session
export TERM=xterm
xterm, vt100 and linux are common names that most hosts have. The session may lose features such as extra colors.
Fix 2: copy the entry into your home folder
Run this on the machine where the name works, for example inside tmux:
infocmp -x tmux-256color
It prints the terminal description as text. The -x option includes user-defined capabilities. On the host, make the private database folder first, then compile the entry into it:
ssh [email protected] 'mkdir -p ~/.terminfo'
infocmp -x tmux-256color | ssh [email protected] 'tic -x -'
The folder matters. The tic manual says that when it cannot write to the system database, it uses $HOME/.terminfo, but only if that directory already exists. The terminfo(5) manual says ncurses looks in $HOME/.terminfo after the TERMINFO variable and before the system locations.
Replace tmux-256color with the name in your message. If the name is xterm-ghostty or xterm-kitty, the terminal has its own tools for this; see xterm-ghostty or xterm-kitty not found after SSH: fix TERM and terminfo.
Fix 3: ask the administrator
The administrator can install the host's terminfo package. Give them the exact name from the message.
Fix 4: change what tmux reports
If you often connect from tmux to hosts that lack tmux-256color, set a name that is common instead in ~/.tmux.conf:
set -g default-terminal "screen-256color"
The manual describes the option as the default TERM for new windows created in the session, so it applies to windows created afterwards. The name still has to be a derivative of screen or tmux, as the manual requires. If colors look wrong rather than the name being unknown, see Colors wrong in tmux: get 256 colors and true color (default-terminal, RGB).
Related
- Scroll back and search history in tmux
- Keep your work after a disconnect with tmux
- Colors wrong in tmux: get 256 colors and true color (default-terminal, RGB)
- xterm-ghostty or xterm-kitty not found after SSH: fix TERM and terminfo
- tmux "open terminal failed: not a terminal" and bash "no job control in this shell" over SSH