Use an alias to quickly list all SSH hosts defined in your SSH config.

I use an SSH config file to manage the details of all the SSH hosts I connect to.

Sometimes I need to audit the hosts in my SSH config.

This can be done using the following:

grep -P "^Host ([^*]+)$" $HOME/.ssh/config | sed 's/Host //'

This command will exclude wildcard definitions leaving you with just the explicitly named hosts.

So that I don't have to remember this everytime, I've added this as an alias to my .zshrc file:

...
# Aliases
# List SSH hosts from SSH config
alias ssh-hosts="grep -P \"^Host ([^*]+)$\" $HOME/.ssh/config | sed 's/Host //'"
...