aboutsummaryrefslogtreecommitdiff
path: root/content/weblog/2021-03-27_fix-broken-terminal-ssh/index.md
blob: 41156b550a6386bcf3242e91f03e20480f67fab2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
+++
title = "Fixing terminal and remote machine misunderstandings"
date = 2021-03-27T16:10:01Z
+++

If you are like me and use a not-so standard terminal emulator and find yourself
frequently ssh'ing into new machines, or maybe you've changed your terminal
emulator, then this article might help you get your terminal fully functional
over ssh.

<!-- more -->

Upon logging in you might notice that several shell features might not work as
expected; clear does nothing, pressing backspace doesn't erase the text on
screen, etc. Or trying to use a program like tmux you might come across a
message like `open terminal failed: missing or unsuitable terminal: <your
terminal>`. This means that the system you've just logged into doesn't know how
to interact with your terminal emulator.

This happens to me on a somewhat regular basis but not frequent enough to
remember how to solve it, and for some reason it is not easy to find the nice
answer I was looking for on the Internet, and so, I decided to write this to
help me remember how to properly solve this problem.

## Solution

The way I solve this is to first generate the terminfo description file on my
local computer. Let's say I am using Alacritty:

```
$ infocmp alacritty > alacritty.terminfo
```

Then copy that file to the remote machine, for example, using rsync:

```
$ rsync alacritty.terminfo remote:
```

Finally on the remote machine import the terminfo file. If you have root access,
you can import using root/sudo so that it is available to all users, otherwise
it will only be available for the user you're currently logged-in as.

```
# tic -x alacritty.terminfo
```

There are several other solutions (and some hacks) like copying the terminfo
directly from your `/lib/terminfo/…` directory to the remote machine's. I,
however, find the solution presented above to be cleaner and handier, since I
usually keep the terminfo file I generated with `infocmp` in case I need to
import it into any other machines, unless I change my terminal, in which case I
regenerate it first.