3

同じサーバー上で異なるユーザーが複数の SSH キーを使用できるようにしたいと考えています。WebホスティングとSSHトンネルの両方に使用するサーバーがあります。SSH トンネリング専用のログイン シェルを持たないアカウントを設定しました。root ユーザーを使用して、システムの残りの部分を管理します。

私は 2 つの SSH キーを持っています。1 つは root ユーザー用のパスワード付きで、もう 1 つは SSH トンネル用のパスワードなしです。トンネル ユーザーとして接続するときはトンネル キーを使用し、ルート ユーザーとして接続するときはルート キーを使用するようにするにはどうすればよいですか?

4

1 に答える 1

4

ルート ユーザー用に 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.
于 2013-02-15T04:29:25.433 に答える