Mac のターミナルとかから、サーバに SSH 接続する際に長ったらしいオプションつけてませんか?
例えば、example.com にユーザー wokamoto、秘密鍵 ~/.ssh/id_rsa.example、ポート番号 10022 で接続する際、こんな感じで接続しますよね。
1 | $ ssh -l wokamoto -p 10022 -i ~/. ssh /id_rsa .example example.com |
こんなん毎回やってたら、メンドクサイし、タイポも心配。
実は ~/.ssh/config てファイルを用意しておくだけで、これらのオプションを省略することができます。
まぁ、みんな知ってるよねとか思ってたんですが、知らん人も居るみたいなので簡単にやり方を解説しておきます。
まずは、こんな感じで ~/.ssh/config を作りましょう。
1 2 3 4 5 | Host example HostName example.com Port 10022 User wokamoto IdentityFile ~/.ssh/id_rsa.example |
その後、パーミッションを設定。
1 | $ chmod 600 ~/. ssh /config |
これで example.com にユーザー wokamoto、秘密鍵 ~/.ssh/id_rsa.example、ポート番号 10022 で接続する際、これだけで接続することができるようになります。
1 | $ ssh example |
もちろん ~/.ssh/config ファイルには、複数のエイリアスを設定しておくこともできますよ。
1 2 3 4 5 6 7 8 9 10 11 | Host hoge HostName 192.168.0.1 Port 22 User wokamoto IdentityFile ~/.ssh/id_rsa.hoge Host fuga HostName fuga.example.com Port 10022 User fuga IdentityFile ~/.ssh/id_rsa.fuga |
他の詳しいオプションとかは、ターミナルで man ssh_config って打てば教えてくれるよ。
ピンバック: SSH の接続を ~/.ssh/config で超簡単にする方法 | ウェブル
ピンバック: Nginx でリダイレクト : dogmap.jp