
1 つのホストが/etc/hosts
次のように定義されている場合はどうなりますか:
192.168.0.100 server
そして、1つは次のように定義されます~/.ssh/config
。
Host server
HostName 192.168.0.101
そして、サーバーに ssh で接続します: ssh server
。
このような対立はどうやって解決されるのでしょうか? どちらか一方が他方よりも優先順位が高いのだと思います。
答え1
これを行うと、ssh server
サーバー部分は実際のホスト名または ssh 内部の「ニックネーム」になります。ssh は最初に .ssh/config でニックネームを検索し、そこに設定が見つかった場合はそれを使用します。設定が見つからない場合は、実際のホスト名であると想定し、/etc/host および dns 経由で解決を試みます。
答え2
このファイルは~/.ssh/config
とは何の関係もありません/etc/hosts
。むしろ、 が存在する場合に が使用する設定ファイルですssh
。
ssh
詳細スイッチ を-v
に使用すると、他の操作を実行する前に がこのファイルを参照していることがわかりますssh
。
~/.ssh/config のホストエントリ
~/.ssh/config
ここでは、ファイルに「skinner」という名前のサーバーのエントリがあります。 3-v
のスイッチを含めることで、デバッグ レベル 3 を有効にしています。
$ ssh -vvv skinner
OpenSSH_6.2p2, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /home/saml/.ssh/config
debug1: /home/saml/.ssh/config line 8: Applying options for *
debug1: /home/saml/.ssh/config line 35: Applying options for skinner
debug1: /home/saml/.ssh/config line 55: Applying options for *
debug3: cipher ok: arcfour [arcfour,blowfish-cbc]
debug3: cipher ok: blowfish-cbc [arcfour,blowfish-cbc]
debug3: ciphers ok: [arcfour,blowfish-cbc]
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 50: Applying options for *
debug1: auto-mux: Trying existing master
...
ssh
上記では、 がこの定義を利用しており、システムの名前解決機能を参照していないことがわかります。
~/.ssh/config にホストエントリがありません
ファイル内に対応するエントリがない場合~/.ssh/config
、ssh
システムの DNS 解決を参照して、指定されたホスト名に接続する方法を調べます。
$ ssh -vvv skinner
OpenSSH_6.2p2, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /home/saml/.ssh/config
debug1: /home/saml/.ssh/config line 8: Applying options for *
debug1: /home/saml/.ssh/config line 55: Applying options for *
debug3: cipher ok: arcfour [arcfour,blowfish-cbc]
debug3: cipher ok: blowfish-cbc [arcfour,blowfish-cbc]
debug3: ciphers ok: [arcfour,blowfish-cbc]
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 50: Applying options for *
debug1: auto-mux: Trying existing master
debug1: Control socket "/home/saml/.ssh/master-saml@skinner:22" does not exist
debug2: ssh_connect: needpriv 0
debug1: Connecting to skinner [192.168.1.3] port 22.
debug1: Connection established.
ssh
ここでは、ホスト名「skinner」の IP アドレスを見つけるためにシステムを参照していることがわかります。
注記:getent
システム上のホスト名を検索するには、次を使用できます。
$ getent hosts skinner
192.168.1.3 skinner.dom.net
答え3
一般に、Unix ソフトウェアの場合、ユーザー固有の設定 (この場合は~/.ssh/config
) はシステム全体の設定 (この場合は/etc/hosts
) よりも優先されるため、 の設定の方~/.ssh/config
が優先されます。