LoginSignup
0
3

More than 5 years have passed since last update.

ssh_config で Host名を動的に設定する

Posted at

やりたいこと

ansiblechef を使ってサーバを簡単に構築できるようになった昨今、デプロイにおいても「新しいサーバを構築して古いサーバを捨てる」といった手法ができるようになっています。
新規で構築されるサーバには無論新しいIPが振られる訳ですが、毎度 .ssh/config に追加していくのは正直ダルいなーと思っていたので、 config いじらずにやる方法ないかなーと思って調べてみました。
が、意外といい情報が見つけられず・・・、、

やったこと

ssh_configProxyCommand を使います。(この子は多段SSH目的でよく使われるようです。)

~/.ssh/config
Host group01-*
  ProxyCommand /bin/nc 172.31.1.$(echo %h |cut -d- -f2) %p

使い方

$ ssh group01-5
=> connect to 172.31.1.5

参考

0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3