When you establish an SSH connection to a remote host from Kitty and start nano or other terminal programs there, this error may occur:

Error opening terminal: xterm-kitty

The remote host does not recognize the Kitty terminal and cannot process the terminal functions correctly.

There is a temporary and permanent solution to this.

Temporary solution

Execute this command on the remote host:

$ export TERM=xterm-256color

Permanent solution

Add this block of config to the .bashrc of the remote host:

# Fix nano and other terminal apps when using Kitty
if [ "$TERM" = "xterm-kitty" ]; then
  export TERM=xterm-256color
fi