# Ghostty, and SSH

Published: 2026-02-10
Source: https://aravindh.net/posts/ghostty_and_ssh/
Tags: Sysadmin, SRE

---


#  Fixing "Error Opening Terminal: xterm-ghostty" and Unlocking Modern SSH

 ### What is Ghostty?

Ghostty is a high-performance terminal emulator written in Zig. Unlike traditional terminals like Terminal.app or GNOME Terminal, Ghostty is GPU-accelerated, providing extremely low latency and high frame rates. 

 ### Why move beyond xterm-256color?

The standard xterm-256color protocol is a legacy standard that limits terminal communication to technology from the early 2000s. While it is highly compatible, it lacks the vocabulary to describe modern terminal features.

Ghostty uses the xterm-ghostty terminfo, which implements modern protocols. By using Ghostty's modern protocol, you gain:

 1. **TrueColor (24-bit):** Support for 16.7 million colors, enabling smooth gradients and sophisticated color schemes in Neovim and other CLI tools.
 2. **Advanced Input:** Proper detection of complex key combinations (e.g., distinguishing between Ctrl+i and Tab).
 3. **Rich Styling:** Native support for undercurls (wavy lines for linter errors), strike-throughs, and modern cursor shapes.
 4. **Clipboard Integration:** Secure and reliable bi-directional clipboard synchronization between remote servers and your local machine.

 ### The Problem: Remote Incompatibility

When you SSH into a remote server, the server checks your $TERM variable. If it sees xterm-ghostty but does not have the corresponding terminfo file in /usr/share/terminfo, interactive applications like nano, htop, or vim will crash with the error: `Error opening terminal: xterm-ghostty`.

 ### Three Ways to Fix and Automate Ghostty SSH

 #### 1. The Native Ghostty Action

If you are connecting to a server without needing additional SSH flags (like custom identity files), use Ghostty’s built-in SSH wrapper. It automatically checks for and installs the necessary terminfo on the remote host before opening the session.

 ```bash
   ghostty +ssh root@A.B.C.D
 ```

 #### 2. The One-Time Manual Injection

For servers you plan to access long-term, you can manually "inject" your local terminfo definition into the remote server's database. Run this once from your local machine:

 ```bash
   infocmp -x | ssh -i ~/.ssh/id_rsa_aravindh.net root@A.B.C.D tic -x -
 ```

This pipes your local Ghostty capabilities to the remote tic (terminfo compiler) utility. Once this is done, standard ssh commands will work perfectly for all future sessions.

 #### 3. Permanent Automation for Custom Options

If your workflow requires custom identity files or specific ports, the most robust solution is to combine an SSH configuration with a shell alias.

Update your ~/.ssh/config
By defining the host in your config, you remove the need to pass flags manually:

 ```text
   Host aux-aravindh
       HostName A.B.C.D
       User root
       IdentityFile ~/.ssh/id_SSH_aravindh.net
 ```

 Step B: Set the Ghostty Alias
 Add this to your ~/.zshrc or ~/.bashrc:

 ```bash
   alias ssh="ghostty +ssh"
 ```

Now, running ssh aux-aravindh will use your specific key AND invoke Ghostty's terminfo injection automatically.



 ### Technical Utility: fix_terminal.sh

 If you frequently interact with new, one-off servers using various flags, you can use the following script to automate the terminfo injection.

 Script: fix_terminal.sh

 ```bash
   #!/bin/bash
   # Usage: ./fix_terminal.sh [ssh-arguments] [user@host]
   # Example: ./fix_terminal.sh -i ~/.ssh/id_rsa_aravindh.net root@46.224.136.170

   # Capture all arguments except the last one as SSH flags
   ARGS="${@:1:$#-1}"
   # Capture the last argument as the destination
   DEST="${@: -1}"

   echo "Injecting xterm-ghostty terminfo to $DEST..."
   infocmp -x | ssh $ARGS $DEST "mkdir -p ~/.terminfo && tic -x -o ~/.terminfo -"

   if [ $? -eq 0 ]; then
       echo "Success. You can now use Ghostty features on $DEST."
   else
       echo "Failed to inject terminfo."
   fi
 ```

