SSH経由でリモートサーバーに接続しようとしましたが、まだパスワードの入力を求められます。

SSH経由でリモートサーバーに接続しようとしましたが、まだパスワードの入力を求められます。

ssh-keygenを使用してsshキーペアを作成し、サーバーにssh-copy-idを使用してAuthorized_keysに公開キーが追加されたことを確認しましたが、ssh -i ~/.ssh/を使用してサーバーに接続しようとしたときにMY_KEY user@まだパスワードを求めています。サーバーにrootアクセス権がありませんが、私の.sshディレクトリには「authorized_keys」ファイルと「known_hosts」ファイルのみがあり、両方とも公開キー「MY_KEY」があります。 /User、/.ssh、および/.sshの2つのファイルに対するすべての権限を確認しましたが、sshd_configにアクセスできませんでした。

接続しようとすると、このように表示されます。

ssh -v -i ~/.ssh/MY_KEY user@serverIP
debug1: Reading configuration data /Users/user/.ssh/config
debug1: /Users/user/.ssh/config line 18: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to serverIP [serverIP] port 22.
debug1: Connection established.
debug1: identity file /Users/user/.ssh/MY_KEY type 0
debug1: identity file /Users/user/.ssh/MY_KEY-cert type -1
debug1: identity file /Users/user/.ssh/gitlabkey type 3
debug1: identity file /Users/user/.ssh/gitlabkey-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4
debug1: match: OpenSSH_7.4 pat OpenSSH_7.0*,OpenSSH_7.1*,OpenSSH_7.2*,OpenSSH_7.3*,OpenSSH_7.4*,OpenSSH_7.5*,OpenSSH_7.6*,OpenSSH_7.7* compat 0x04000002
debug1: Authenticating to serverIP:22 as 'user'
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:oF1yjVJjhgf9N7u84hk8QqZrY
debug1: Host 'serverIP' is known and matches the ECDSA host key.
debug1: Found key in /Users/user/.ssh/known_hosts:17
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: Will attempt key: /Users/user/.ssh/MY_KEY RSA SHA256:W3JxHToIyelBpl4 explicit
debug1: Will attempt key: /Users/user/.ssh/gitlabkey ED25519 SHA256:KAd+YwkK6dWptbtLvWg explicit
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,password
debug1: Next authentication method: publickey
debug1: Offering public key: /Users/user/.ssh/MY_KEY RSA SHA256:W3JxHToIyelB6Upl4 explicit
debug1: Authentications that can continue: publickey,password
debug1: Offering public key: /Users/user/.ssh/gitlabkey ED25519 SHA256:KAd+YwkK6dWtvWg explicit
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
user@serverIP's password:

正直なところ、他に何を試すべきかわかりません。正しいキー(MY_KEY)を試みる理由はわかりませんが、明らかに失敗します。

ベストアンサー1

同じ問題を抱えている方のために… 長い時間が経ってこそ解決できました。

試すのに疲れてAuthorized_keysとKnown_hostsを削除し、私が持っていたのは空の.sshディレクトリだけでした。その瞬間、私はサーバーとの接続を切断し、すべてが壊れたと思いましたが、Macを使用しているのでhttps://coderwall.com/p/8ag5aq/ssh-broken-pipe-fix-mac-os-x再接続できます。

Mac で ssh-copy-id コマンドを再実行すると、サーバーに「known_hosts」の代わりに「authorized_keys」ファイルが自動的に生成されます。

それはすべてです。その後、ssh -i /path/to/MYKEY user@serverIPを実行しましたが、パスワードの入力を求められず、魅力のように動作しました。

おすすめ記事