peco

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 () {
  peco_query=$@
  target=$(grep -iE "^host[[:space:]]+[^*]" ~/.ssh/config|grep -v "*"|awk "{print \$2}" | peco --query="$peco_query")
  if [ ! -z $target ]; then
    ssh $target
  fi
}

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.

HOST rickynews-dev.com
  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.

ubuntu01.rickydev.net 103.245.222.133
ubuntu02.rickydev.net 103.243.193.134
fedora01.rickydev.net 103.245.222.137

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

HOST *.rickydev.net
  IdentityFile ~/.ssh/credentials/rickynews.pem
HOST fedora*.rickydev.net
  User     fedora
HOST ubuntu*.rickydev.net
  User     ubuntu
HOST amazon*.rickydev.net
  User     ec2-user
HOST ubuntu01.rickydev.net
HOST ubuntu02.rickydev.net
HOST fedora01.rickydev.net

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.