<!--
  canonical-url: https://www.avonture.be/blog/zsh-plugin-ssh-config-suggestions
  published:     2025-02-13
  This is a static plain-Markdown mirror generated at build time.
  Visit the canonical URL above for the fully rendered page, with images and interactive components.
-->

# SSH - Autosuggestions with ZSH

> Get instant SSH autosuggestions in ZSH. Learn to install the zsh-ssh-config-suggestions plugin and display all your ~/.ssh/config aliases with a simple TAB press.

---
![SSH - Autosuggestions with ZSH](/img/v2/ssh.webp)

**TL;DR**

Stop memorizing server IPs and SSH commands. This article shows you how to streamline your SSH workflow with `zsh-ssh-config-suggestions`, a ZSH plugin that provides autosuggestions for your SSH connections. By leveraging your `~/.ssh/config` file, this plugin allows you to simply type `ssh ` and press Tab to see a list of all your configured server aliases. Learn how to install and configure this handy plugin to make connecting to your servers faster and more efficient.

A few weeks ago, I've posted a [SSH - Launch a terminal on your session without having to authenticate yourself](/blog/linux-ssh-scp#using-the-config-file) article about the `ssh` command in Linux.

I'm pretty sure, like me, you are tired of typing command lines like `ssh christophe@1.2.3.4` to start an SSH connection because ... you know, you don't need to connect on a server; no, you need to connect to the server where the application is running; you know the name of the *MyAmazingApp* application but certainly not the name of the server or its IP.

That's the case for me anyway.

So, I need to connect to my vault, in which I list all the information about applications, server names, credentials to be used, ...

It would be pretty cool to run `ssh MyAmazingApp` no?

*Two neighbours: [How to connect to your hosting server using SSH](/blog/connect-using-ssh-to-your-hosting-server) to fill that `~/.ssh/config` in the first place, and [Master your ssh command and select the host from a list](/blog/ssh-with-fuzzy-finder) when autocompletion is no longer enough — around fifty hosts, a searchable list beats `TAB`.*

Here's the result: type `ssh ` (with the trailing space) and press `TAB` to get every alias from your `~/.ssh/config` file, autosuggested.

![Using ssh-config-suggestions](./images/zsh-plugin-ssh-config-suggestions.gif)

> **You should add a space character after `ssh`:**
>
> To make it working, please note: you should add a space character after having typed `ssh` and before pressing `tab`.

## Why It Works

The plugin reads the `Host` aliases already declared in your `~/.ssh/config` file and wires them into ZSH's completion system — no separate list to maintain, no vault to open, just the config file you already have.

It should be really nice to be able to run `ssh MyAmazingApp` and hop, I'm connected on the server.

This is where the `~/.ssh/config` is so helpful (please refer to this [article](/blog/linux-ssh-scp#using-the-config-file)) but we can go one step further: it would be so great to type `ssh` and by some magic, Linux will show you the list of aliases defined in the `~/.ssh/config` file. Let's install it.

## Seeing It in Action with Docker

No real server is ever contacted by this plugin — it only reads `Host` aliases from a config
file — which makes it a perfectly safe one-command Docker test.

> **Why Docker first?:**
>
> The Dockerfile below installs Oh-My-Zsh and the plugin, enables it in `~/.zshrc`, and writes the
> exact `~/.ssh/config` shown further down. Nothing on your own machine changes, and nothing tries
> to actually connect anywhere.

**Dockerfile**

```docker
FROM ubuntu:24.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        zsh \
        git \
        curl \
        ca-certificates && \
    rm -rf /var/lib/apt/lists/*

# Install Oh-My-Zsh unattended (host framework required by the plugin)
RUN sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" \
    "" --unattended --keep-zshrc

# Install zsh-ssh-config-suggestions and enable it in the default plugins=() list
RUN git clone --depth=1 https://github.com/yngc0der/zsh-ssh-config-suggestions.git \
        /root/.oh-my-zsh/custom/plugins/zsh-ssh-config-suggestions && \
    sed -i 's/^plugins=(git)/plugins=(git zsh-ssh-config-suggestions)/' /root/.zshrc

# The exact ~/.ssh/config from this article — no real hosts are ever
# contacted, only the Host aliases are read for completion
RUN mkdir -p /root/.ssh && \
    printf '%s\n' \
    'Host MyAmazingApp_PROD' \
    '    Hostname 1.2.3.4' \
    '    User usr_app_prod' \
    '' \
    'Host MyAmazingApp_TEST' \
    '    Hostname 6.7.8.9' \
    '    User usr_app_test' \
    '' \
    'Host YourAmazingApp' \
    '    Hostname 1.2.3.4' \
    '    User you' \
    '' \
    'Host LegacyApp' \
    '    Hostname 1.2.3.4' \
    '    User legacy' \
    > /root/.ssh/config && \
    chmod 600 /root/.ssh/config

# Signal clearly that this shell runs inside a container
RUN echo "PROMPT='%B%F{yellow}🐳 %F{cyan}%n%f%b %~ %# '" >> /root/.zshrc

CMD ["/bin/zsh", "-i", "-l"]
```

Build and run it:

```bash
$ docker build -t ssh-suggest-demo .
[+] Building 20.7s (8/8) FINISHED
✔ exporting to image
$ docker run --rm -it ssh-suggest-demo
🐳 root ~ # ssh
```

Type `ssh ` (with the trailing space) and press `TAB` — the same four aliases from the
"Use it" section below (`MyAmazingApp_PROD`, `MyAmazingApp_TEST`, `YourAmazingApp`,
`LegacyApp`) show up immediately, read straight from the pre-baked `~/.ssh/config`.

## Installation of the zsh-ssh-config-suggestions plugin

This assumes Oh-My-Zsh is already installed (see [How to install Oh-My-ZSH](/blog/zsh-install) if not). Just clone the official repository by running this command: `git clone https://github.com/yngc0der/zsh-ssh-config-suggestions.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-ssh-config-suggestions`. You'll get a local copy of the plugin in your `Oh-my-zsh` plugin folder.

Then edit the `~/.zshrc` file, search for `plugins=(` and add `zsh-ssh-config-suggestions` to the list. You'll have f.i. something like:

**\~/.zshrc**

```bash
plugins=(
  git
  # ... your existing plugins
  zsh-ssh-config-suggestions
)
```

Close your console, open a new one (or run `source ~/.zshrc` to load your change) and it's done.

## Use it

Imagine I've this content in my `~/.ssh/config`:

**\~/.ssh/config**

```
Host MyAmazingApp_PROD
    Hostname 1.2.3.4
    User usr_app_prod

Host MyAmazingApp_TEST
    Hostname 6.7.8.9
    User usr_app_test

Host YourAmazingApp
    Hostname 1.2.3.4
    User you

Host LegacyApp
    Hostname 1.2.3.4
    User legacy
```

Now, I really don't need to remember anything and I don't even need to know the names of the aliases any more!

I just need to type (it's important): `ssh ` followed by `TAB` and I get the same suggestions already shown at the top of this article.

As you can see, the system will display the list of hosts defined in my configuration file! I can then edit the file, add a new application and hop, next time, I'll get its name in the list. I don't need to connect to my vault anymore. Nice no?

This is just one plugin among many; if your `~/.zshrc` is starting to grow with this kind of customization, have a look at [Beyond the Monolith - Organizing Your ZSH Workflow Like a Pro](/blog/modular-zsh-workflow) to keep it maintainable.
