Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mamemomonga
Last active December 4, 2020 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mamemomonga/e28518bc8e13f24e61d329a1c87dc9b2 to your computer and use it in GitHub Desktop.
Save mamemomonga/e28518bc8e13f24e61d329a1c87dc9b2 to your computer and use it in GitHub Desktop.
ssh_configのホスト名を検索するツール

ssh_configのホスト名を検索するツール

最近のssh clientでは ~/.ssh/config に Include conf.d/* とすることで、~/.ssh/conf.d 以下にユーザのconfigファイルを分離することができるようになった。 しかし、自分で設定したホストを憶えきれないので、検索するためのシンプルなシェルスクリプトを作成した。

ssh-hosts-find を引数なしで実行すると、一覧が表示される。引数をつけると、それをキーにしてgrepする

#!/bin/bash
# vim:ft=sh
set -eu
allhosts() {
find ~/.ssh/conf.d -type f -exec cat {} \; | perl -nlE "say \$1 if(/^Host (.+)$/)"
}
if [ -z "${1:-}" ]; then
allhosts
else
allhosts | grep $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment