DEV Community

olistik
olistik

Posted on

Show the hosts configured in your SSH config file

Recently I had to connect via SSH to several hosts. It's hard for me to remember their full domain, not to mention all the options required (identity file, port, etc.) to connect.

The SSH config file (~/.ssh/config) is the best place to store this information but then again I have to remember all the name I used for such hosts..

No memory

To make my life even more comfortable, I created this little Ruby script that shows a sorted list of the hosts present in the SSH config file:

Behold! 🧙🏼‍♂️

#!/bin/zsh

cat ~/.ssh/config | ruby -e "puts STDIN.each_line.map {|l| l.match(/^Host\ (.*)$/)}.compact.map {|r| r[1]}.sort"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)