ルート ユーザー用に 1 つのキーを設定し、トンネル ユーザー用にもう 1 つ (サーバー/リモート マシン上のファイルauthorized_keysを介して) セットアップした場合、正しいキーが自動的に選択されます。
これは、キーをロードしてユーティリティssh-agent
で使用できるという前提に基づいています。ssh
それ以外の場合は、 を使用して手動でキーを指定できますssh -i <identity file>
。
それに加えて、ssh_config ファイル ( ~/.ssh/configまたは/etc/ssh/ssh_config )でエイリアスを設定できます。
Host server-root
User root
IdentityFile <path to your key>
Hostname <real hostname>
Host server-tunnel
User tunnel-user
IdentityFile <path to your key>
Hostname <real hostname>
次に、またはのいずれかを使用しssh server-root
ますssh server-tunnel
。
しかし、ssh-agent を使用するのが最も簡単な設定かもしれません。
ssh-agent を使用せずに適切なキーを自動選択する場合は、 を介して両方のキーを指定できます-i
。
OpenSSH の man ページから引用するには:
-i identity_file
Selects a file from which the identity (private key) for public
key authentication is read. The default is ~/.ssh/identity for
protocol version 1, and ~/.ssh/id_dsa, ~/.ssh/id_ecdsa and
~/.ssh/id_rsa for protocol version 2. Identity files may also be
specified on a per-host basis in the configuration file. It is
possible to have multiple -i options (and multiple identities
specified in configuration files). ssh will also try to load
certificate information from the filename obtained by appending
-cert.pub to identity filenames.