Peco is a well-known interative filtering tool for all developers. Once installed it on your system, you will definitely find its benefit and soon like it. Today, I’m gonna give you some tips about peco for managing messy ssh connections.

Set up to your zshrc/bashrc

The initial setup is pretty easy. Just paste following code into your ~/.zshrc

function s () {
  target=$(grep -iE "^host[[:space:]]+[^*]" ~/.ssh/config|grep -v "*"|awk "{print \$2}" | peco --query="$peco_query")
  if [ ! -z $target ]; then
    ssh $target

Then, you can type it on your terminal.

$ s

s command is searching our /.ssh/config and showing them up with an interative UI with peco. We can choose and make a ssh connection to a server easily with typing just a few words.

If you would like to add more ssh servers on the list, just putting it on your ~/.zshrc like below.

  User         ricky
  IdentityFile ~/.ssh/credentials/rickynews.pem

TIPS: Domain management with Route53

If you have a bunch of private testing servers on AWS, it’s pretty hard to remember what services are working on on each IP addresses. If so, use Amazon Route 53 and assign tentative A record for them.

Also insert few lines to your ~/.ssh/config like below.

  IdentityFile ~/.ssh/credentials/rickynews.pem
HOST fedora*
  User     fedora
HOST ubuntu*
  User     ubuntu
HOST amazon*
  User     ec2-user

If you don’t have your own DNS server, of course, setting them on your hosts files also fine. After this configuration, your can choose your ssh servers faster and easiler and connect them.

Sample ssh domain names were automatically generated by mockaroo, no attacking intended.