58

When I run

screen

on the remote host(running Linux), I obtain the following error:

Cannot find terminfo entry for 'xterm-256color'.

I am running terminal on Mac OSX Lion to access the remote host. I have googled to find out the solution to this problem and it appears that people suggest doing

export TERM=xterm-color

which doesn't work for me.

Please help.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Vinayak Agarwal
  • 1,350
  • 3
  • 15
  • 28

13 Answers13

83

Find out which TERM is supported:

ls /usr/share/terminfo/x

this will give you a list of supported TERMs i.e.

xterm
xterm-xfree86

set the environment variable:

export TERM=xterm-xfree86

and run screen:

TERMINFO='/usr/share/terminfo/' screen
BigSN
  • 973
  • 7
  • 13
  • 4
    i didn't have to run screen with last command, running `screen` worked – danidee Aug 17 '16 at 14:57
  • 1
    in `10.11.5` I don't seem to have a folder `/usr/share/terminfo/x` however `find /usr/share/terminfo/ -type f -print` which I found at https://unix.stackexchange.com/questions/30058/how-can-i-check-which-terminal-definitions-are-available does return a list – Ben Creasy Jul 13 '17 at 04:40
  • 5
    Ran into this problem on a QNAP NAS, this fixed the issue. Thanks! – 0x01 Apr 09 '18 at 20:23
  • 2
    I am working on a QNAP NAS as well. I just added `export TERMINFO='/usr/share/terminfo/'` to the `.bashrc` so now it and any other aliases are handled automatically. **This will be reverted when you update the firmware,** so you should document adds/changes like this someplace off the system so they can be added if the new firmware image if it isnt fixed on that already. Screen is good for keeping a shell session live if you don't want to mess with shell timeouts which are mandated by security settings. I had to add the path as well. – Rowan Hawkins Sep 12 '18 at 20:24
  • I've tested this solution on a Synology NAS running DSM 7. The issue I had is that I use a non-standard terminal ([kitty](https://github.com/kovidgoyal/kitty/) which requires its own terminfo file. The NAS _had_ the terminfo in the correct place (when I `ssh` in, I _know_ I've got the right term!), but, alas, when launching `screen` from a cron job, it didn't set the `$TERMINFO` env. var. Apparently it really requires setting it beforehand. Thanks for the tip! (comment made here on behalf of those future Synology NAS users attempting to do the same and furiously googling for a solution) – Gwyneth Llewelyn Feb 01 '22 at 17:21
13

In the terminal app you are using to ssh, go to preferences -> advanced -> Declare terminal as: -> xterm-color (or something besides xterm-256color)

This answer was taken from a comment to this post, which has another solution: http://marcoschuh.de/wp/?p=873

bennlich
  • 1,207
  • 10
  • 21
11

In case of my Buffalo Linkstation I solved it this way:

cd /lib/terminfo/x
ln -s xterm-color xterm-256color
  • This is a simple and long-term solution, thank you ;) (although my path was `/usr/share/terminfo/x`) – fiz Nov 14 '19 at 13:30
7

You're missing a terminfo file on the remote machine which matches 'xterm-256color'.

Screen doesn't know how to emulate the terminal you've asked for (xterm-256color) because it doesn't have the file which describes the terminal you're using (xterm-256color).

You could change the ENV variable TERM to ask for a terminal emulation which the remote machine does have. For example: export TERM=vt220, but that would assume your remote has a vt220 terminfo file, and you wouldn't get pretty colors, and you'd have to do other tedious things to make it stick. Better...

If your local machine has terminfo files but your remote machine doesn't, for example, a linux/macos talking to a QNAP/QNAS/busybox/rpi/router/modem/IOTdevice then...

You can copy the necessary file over to it and instruct your remote terminal to use it for screen. eg:

[local] $ scp /lib/terminfo/x/xterm-256color john@nasbox:xterm-256color
[local] $ ssh john@nasbox
[remote] $ ls
xterm-256color
[remote] $ TERMINFO='/share/homes/john/xterm-256color' screen

Screen should work at this point. Your local machine might have the terminfo directory someplace else (/etc/terminfo/ and /usr/share/terminfo/ are common alternatives; you might have to dig around to find yours).

To set it up more permanently move it to a '.terminfo' directory in your home directory (or elsewhere if you know better). eg:

[remote] mkdir -p .terminfo/x
[remote] mv xterm-256color .terminfo/x
[nasbox] screen

The same technique should apply to other terminal emulations. The ENV variable TERM determines which terminal it should try to emulate and the file of the same name provides the magic codes to make it all happen.

John Mee
  • 50,179
  • 34
  • 152
  • 186
  • According to [this](https://bbs.archlinux.org/viewtopic.php?pid=774822#p774822), that's the right thing to do, instead of just setting some random TERM value. However, I have no knowledge to confirm that. In any case, it did work for me. – caxcaxcoatl Dec 31 '20 at 14:43
  • This is the correct approach for a robust, long-term solution to missing terminfo entries. Having the `TERM` environment variable set correctly means the user benefits from the actual capabilities of the terminal they're using, e.g., one reason I chose Tmux over GNU screen is that it supports italic text. When I connect to old RHEL 6 servers, I copy the `tmux` and `tmux-256color` compiled terminfo entries into `~/.terminfo/t`. This means I can log in using any terminal device without having to mess with the `TERM` environment variable. – Anthony Geoghegan Sep 16 '21 at 11:27
6

I've previously used the default Mac OS X Terminal app to access my Ubuntu-based tmux via ssh, and found the problem you described - my bash and tmux is set to screen-256color, an option not even in the list in the Mac Terminal preferences.

I tried adding the line:

export TERM=screen-256color

as a startup command, but it was ignored and was overridden with xterm-color upon startup.

I also managed to change the settings for the Mac Terminal to screen-256color by choosing Shell > Export Settings, and then editing the XML file it generated, finding the line xterm-color and changing it to screen-256color, then Shell > Importing this settings file. Upon launching the Terminal, however, I found it had still overridden this setting with xterm-color.

So I conceded and downloaded iTerm2 which allowed me to change the screen-256color setting by typing it into a plain text field (rather than choosing from a limited pulldown menu). This worked straight away without even having to close and reopen the console.

So in conclusion, I recommend using iTerm2 rather than the default Mac Terminal (which doesn't seem to allow the changes to $TERM you require).

wayfarer_boy
  • 1,489
  • 21
  • 22
6

You can install ncurses-term on the remote server (Debian/Ubuntu) to fix the issue.

grokavi
  • 106
  • 1
  • 3
4

I was able to change Mac OSX(10.7.5) terminal(v2.2.3, 303.2) emulation from the menu Terminal>Preferences>Settings>Advanced>Emulation Declare terminal as xterm-color

Opening a new terminal ssh connection enabled the new setting.

Aussiehash
  • 41
  • 1
3

You probably need to install a package on your Linux host which provides one of the following files:

/usr/share/terminfo/x/xterm-256color
/lib/terminfo/x/xterm-256color

On Ubuntu, for example, this is provided by the ncurses-base package.

djpohly
  • 711
  • 5
  • 8
3

An other case, e.g. upgrading to Debian Buster from inside screen.

Terminfo xterm-256colour format changed, so screen cannot restore the previous session.

You may use export TERM=xterm to close screen sessions, and then restart screen. This time it will use the correct terminfo file, and so it will succeed.

Source: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=901843

Giacomo Catenazzi
  • 8,519
  • 2
  • 24
  • 32
0

In the question, the user's configuration asked for a terminal description which was not the default screen. This was eventually fixed by an update from Apple. In the version cited in the question, Apple did not provide that terminal description. They do now (and have since 2015). For the record, here is a directory listing showing the related entries for MacPorts (in /opt/local), a locally built ncurses (in /usr/local) and the Apple/system files in /usr/share:

-rw-r--r--   1 root         1912 Oct  3 2015    opt/local/share/terminfo/73/screen-256color
-rw-r--r--   1 root         1924 Oct  3 2015    opt/local/share/terminfo/73/screen-256color-bce
-rw-r--r--   1 root         1954 Oct  3 2015    opt/local/share/terminfo/73/screen-256color-bce-s
-rw-r--r--   1 root         1940 Oct  3 2015    opt/local/share/terminfo/73/screen-256color-s
-rw-r--r--   1 root         1912 Apr 12 04:22   usr/local/ncurses/share/terminfo/73/screen-256color
-rw-r--r--   1 root         1924 Apr 12 04:22   usr/local/ncurses/share/terminfo/73/screen-256color-bce
-rw-r--r--   1 root         1954 Apr 12 04:22   usr/local/ncurses/share/terminfo/73/screen-256color-bce-s  
-rw-r--r--   1 root         1940 Apr 12 04:22   usr/local/ncurses/share/terminfo/73/screen-256color-s
-rw-r--r--   1 root         1828 Aug 22 2015    usr/share/terminfo/73/screen-256color
-rw-r--r--   1 root         1840 Aug 22 2015    usr/share/terminfo/73/screen-256color-bce
-rw-r--r--   1 root         1866 Aug 22 2015    usr/share/terminfo/73/screen-256color-bce-s
-rw-r--r--   1 root         1856 Aug 22 2015    usr/share/terminfo/73/screen-256color-s

You may notice a few details:

  • on OSX, the default file-system ignores case, so the s is encoded in hexadecimal (to make it distinct from S)

  • the entries have slightly different sizes. Apple provided an older version of the terminal database, which lacks some features.

  • Using toe, I see this:

    --> /usr/local/ncurses/share/terminfo
    ----> /usr/share/terminfo
    ------> /opt/local/share/terminfo
    *-*-*-: screen-256color GNU Screen with 256 colors   
    *-*-*-: screen-256color-bce     GNU Screen with 256 colors and BCE 
    *-*-*-: screen-256color-bce-s   GNU Screen with 256 colors using BCE and status line
    *-*-*-: screen-256color-s       GNU Screen with 256 colors and status line

and comparing the system versus MacPorts:

--- macports    2017-04-26 04:38:21.000000000 -0400
+++ system      2017-04-26 04:40:08.000000000 -0400
@@ -1,19 +1,19 @@
-#      Reconstructed via infocmp from file: /opt/local/share/terminfo/73/screen-256color
+#      Reconstructed via infocmp from file: /usr/share/terminfo/73/screen-256color
 screen-256color|GNU Screen with 256 colors,
        am, km, mir, msgr, xenl,
-       colors#256, cols#80, it#8, lines#24, pairs#32767,
+       colors#256, cols#80, it#8, lines#24, ncv#3, pairs#32767,
        acsc=++\,\,--..00``aaffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
        bel=^G, blink=\E[5m, bold=\E[1m, cbt=\E[Z, civis=\E[?25l,
        clear=\E[H\E[J, cnorm=\E[34h\E[?25h, cr=^M,
        csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
        cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C,
        cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\EM,
-       cvvis=\E[34l, dch=\E[%p1%dP, dch1=\E[P, dim=\E[2m,
-       dl=\E[%p1%dM, dl1=\E[M, ed=\E[J, el=\E[K, el1=\E[1K,
-       enacs=\E(B\E)0, flash=\Eg, home=\E[H, ht=^I, hts=\EH,
-       ich=\E[%p1%d@, il=\E[%p1%dL, il1=\E[L, ind=^J, is2=\E)0,
-       kbs=^H, kcbt=\E[Z, kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC,
-       kcuu1=\EOA, kdch1=\E[3~, kend=\E[4~, kf1=\EOP, kf10=\E[21~,
+       cvvis=\E[34l, dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM,
+       dl1=\E[M, ed=\E[J, el=\E[K, el1=\E[1K, enacs=\E(B\E)0,
+       flash=\Eg, home=\E[H, ht=^I, hts=\EH, ich=\E[%p1%d@,
+       il=\E[%p1%dL, il1=\E[L, ind=^J, initc@, is2=\E)0, kbs=^H,
+       kcbt=\E[Z, kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA,
+       kdch1=\E[3~, kend=\E[4~, kf1=\EOP, kf10=\E[21~,
        kf11=\E[23~, kf12=\E[24~, kf2=\EOQ, kf3=\EOR, kf4=\EOS,
        kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~,
        khome=\E[1~, kich1=\E[2~, kmous=\E[M, knp=\E[6~, kpp=\E[5~,
@@ -22,6 +22,6 @@
        rmul=\E[24m, rs2=\Ec\E[?1000l\E[?25h, sc=\E7,
        setab=\E[%?%p1%{8}%<%t4%p1%d%e%p1%{16}%<%t10%p1%{8}%-%d%e48;5;%p1%d%;m,
        setaf=\E[%?%p1%{8}%<%t3%p1%d%e%p1%{16}%<%t9%p1%{8}%-%d%e38;5;%p1%d%;m,
-       sgr=\E[0%?%p6%t;1%;%?%p1%t;3%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p5%t;2%;m%?%p9%t\016%e\017%;,
+       sgr=\E[0%?%p6%t;1%;%?%p1%t;3%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;m%?%p9%t\016%e\017%;,
        sgr0=\E[m\017, smacs=^N, smcup=\E[?1049h, smir=\E[4h,
        smkx=\E[?1h\E=, smso=\E[3m, smul=\E[4m, tbc=\E[3g,
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
0

I had the same problem in a totally different context.

By typing infocmp I got the message that it could not open terminfo. But it also informed the path it was trying to get. What I did was simply creating that path with the right term there (xterm-256color). Using find * I found it in another directory and copied to the new directory.

user24302
  • 1
  • 1
-2

You just need to copy /usr/share/terminfo/x/xterm-256color to the server that you're connecting to.

erwin
  • 442
  • 6
  • 13
-2

Don't forget to refresh terminal source if you export a variable...

source ~/.bashrc or just open a new terminal. May be why original poster had trouble with exporting.

WSmart
  • 1