同じローカルユーザーのキーストロークログインを介して2つの異なるユーザー名を使用して同じリモートサーバーにログインする方法は?

同じローカルユーザーのキーストロークログインを介して2つの異なるユーザー名を使用して同じリモートサーバーにログインする方法は?

リモートサーバーwww.example.comがあります。

SSHキーを使ってログインすると、すべてが大丈夫に見えます。いくつかのチュートリアルを読んで、秘密鍵と公開鍵のペアを設定しました。

ログインは次のとおりです。

ssh -lusername example.com #it's working fine

しかし、同じサーバーで別のユーザー名でログインしたいと思います。混乱しています。

ssh -lroot example.com #it's NOT working fine, I have to enter the password

この状況ではどうすればよいですか?

ちなみに、ルートディレクトリにはすでに友達が取得したAuthorized_keysファイルがあるので(私たちはサーバーを共有します)、新しい公開鍵を作成して元の鍵に追加しました。

ありがとう

ベストアンサー1

これは働きます:

ssh [email protected]
ssh [email protected]

ルート/ユーザー名の秘密鍵が正しく区別されない場合は、次のように明示的に呼び出すことができます。

ssh -i ~/.ssh/username_id_rsa [email protected]
ssh -i ~/.ssh/root_id_rsa [email protected]

2番目のオプションがまだ機能していない場合は、リモートサーバーの公開鍵設定に問題があります。/var/log/secure詳細については、リモートホストのファイルまたはファイルを確認してください。/var/log/auth

調べる:

  1. このディレクトリの権限は.ssh700です。
  2. ファイル権限はauthorized_keys600です。

編集してください。次のようにすることもできます。

touch ~/.ssh/config
vi ~/.ssh/config

#Add the following:

Host usernameHostname
HostName example.com
User username
IdentityFile ~/.ssh/username_id_rsa

Host rootHostname
HostName example.com
User root
IdentityFile ~/.ssh/root_id_rsa

# Save the file with ' :wq '

Now just type:

ssh usernameexample
[OR]
ssh rootexample

おすすめ記事