web-dev-qa-db-ja.com

間違った場所を見ているSSHキー認証?

私はLinuxの世界ではかなり新しく、Ubuntuサーバー16.04をセットアップしています。

ssh-keygenを使用してキーを生成し、/home/ther4nd0moo/.ssh/id_rsaにキーを保存できました

次にssh-copy-id ther4nd0moo@my_ipを使用し、authorized_keysファイルが正しい場所にあることを確認しました。

別のコンピューターでssh -v ther4nd0moo@my_ipを使用すると、いくつかの奇妙なことがポップアップします(少なくとも私には)

OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 10.0.0.189 [10.0.0.189] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/edgar/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/edgar/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/edgar/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/edgar/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/edgar/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/edgar/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/edgar/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/edgar/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 10.0.0.189:22 as 'need206'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: Host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server Host key: ecdsa-sha2-nistp256 SHA256:YzQwUoOherHwxOOhzEhue7ecx+OMi0FpmIcSONi8X1o
debug1: Host '10.0.0.189' is known and matches the ECDSA Host key.
debug1: Found key in /home/edgar/.ssh/known_hosts:3
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/edgar/.ssh/id_rsa
debug1: Trying private key: /home/edgar/.ssh/id_dsa
debug1: Trying private key: /home/edgar/.ssh/id_ecdsa
debug1: Trying private key: /home/edgar/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

私を悩ませているのは、/home/edgar/(サーバーをインストールするときに入力した私の名前はedgarです)でIDファイルと秘密鍵を検索する方法です。これを解決するために、/home/ther4nd0mmoo/.sshからキーの内容をコピーし、フォルダー/home/edgar/.sshを作成しました。おそらくFound key in /home/edgar/.ssh/known_hosts:3というメッセージが表示されますが、サーバーにアクセスできません。

ssh -i /home/ther4nd0moo/.ssh/id_rsa ther4nd0moo@my_ipを試してみましたが、私の端末ではnot accessible: No such file or directoryと表示されます

私は何か間違っていますか?

2
ther4nd0moo

SSHキーは、ローカルマシンにプライベートキーを持ち、リモートマシンに対応するパブリックキーを持つことで機能します。

そのため、ssh-keygenを実行したときに、プライベート(~/.ssh/id_rsa)とパブリック(~/.ssh/id_rsa.pub)の2つのキーを作成しました。

ローカルマシンのPubicキーファイル(~/.ssh/id_rsa.pub)の内容を、リモートマシンの~/.ssh/authorizedkeysファイルにコピーする必要があります。新しい行に追加するだけです。

異なるローカルマシンからリモートマシンにログインする場合は、元のマシンから2番目のローカルマシンにid_rsaファイルをコピーするか、(より良い)2番目のプライベート/公開鍵ペアを作成する必要があります。ローカルマシン、および2番目のマシンの公開キーをリモートサーバーにコピーします。

リモートサーバーは~/.ssh/authorizedkeysに任意の数の公開キーを保持できます。ローカルマシンごとに異なるキーペアを使用することをお勧めします(信じています)。

リモートマシンから別のマシンにsshする必要がある場合(リモートマシンからラップトップにsshする必要がある場合など)、リモートマシンを独自の秘密/公開キーペアでセットアップし、リモートをコピーしますラップトップの~/.ssh/authorizedkeysファイルへのマシンの公開キー。

次のように考えてください:すべてのマシンにドアキー(秘密キー)があり、他のすべてのマシンにキーホール(authorizedkeysファイル)があります-別のマシンにキーが適合するキーホール設定がある場合、アクセスできます。逆方向で作業するには、別の鍵と鍵穴の設定をセットアップする必要があります。 (おそらく十分に説明されていない-しかし、私はそれが役立つことを願っています!)。

ssh-copy-idコマンドは、基本的に、手動で実行することを保存するためのショートカットコマンドです。

個人的には、難しいことをするのが好きだからといって、公開鍵を手動でコピーすることを好みます。 ;)

3
JamesBB