最近の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 |