SSH公開鍵はサーバーに送信されません。

SSH公開鍵はサーバーに送信されません。

私は多くのウェブサイトを閲覧しましたが、役に立ちませんでした。だから私が間違っていることを他の人が見ることができるかどうかを確認する必要があります。

Ubuntu 18を使用しています。これはssh -v出力です:


debug1: Found key in /home/leithner/.ssh/known_hosts:1
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: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:5nOs3DjENMsvwbU2jHNE2GOv6u/1L5TyFCgc3zPYNDM /home/leithner/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/leithner/.ssh/id_dsa
debug1: Trying private key: /home/leithner/.ssh/id_ecdsa
debug1: Trying private key: /home/leithner/.ssh/id_ed25519
debug1: Next authentication method: password

ssh with port output:
Host '[elm.pa...]:53999' is known and matches the ECDSA host key.
debug1: Found key in /home/leithner/.ssh/known_hosts:1
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: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:5nOs3DjENMsvwbU2jHNE2GOv6u/1L5TyFCgc3zPYNDM /home/leithner/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/leithner/.ssh/id_dsa
debug1: Trying private key: /home/leithner/.ssh/id_ecdsa
debug1: Trying private key: /home/leithner/.ssh/id_ed25519
debug1: Next authentication method: password

From /var/log/auth.log file:
Aug 19 14:44:55 birch sshd[22485]: Accepted publickey for leithner from 129.244.22.126 port 57912 ssh2: RSA SHA256:qLTekbB8a22YWHqRHPZjVSJ0dNEHTSoI3nFN97PEyuc
Aug 19 14:44:55 birch sshd[22485]: pam_unix(sshd:session): session opened for user leithner by (uid=0)
Aug 19 14:44:55 birch systemd-logind[1059]: New session 38875 of user leithner.
Aug 19 14:45:01 birch CRON[22582]: pam_unix(cron:session): session opened for user root by (uid=0)

Aug 19 14:43:44 birch sshd[22367]: pam_unix(sshd:session): session closed for user leithner
Aug 19 14:44:55 birch sshd[22485]: Accepted publickey for leithner from 129.244.22.126 port 57912 ssh2: RSA SHA256:qLTekbB8a22YWHqRHPZjVSJ0dNEHTSoI3nFN97PEyuc
Aug 19 14:44:55 birch sshd[22485]: pam_unix(sshd:session): session opened for user leithner by (uid=0)
Aug 19 14:44:55 birch systemd-logind[1059]: New session 38875 of user leithner.
Aug 19 14:45:01 birch CRON[22582]: pam_unix(cron:session): session opened for user root by (uid=0)
Aug 19 14:45:01 birch CRON[22582]: pam_unix(cron:session): session closed for user root
Aug 19 14:47:25 birch sshd[22567]: Received disconnect from 129.244.22.126 port 57912:11: disconnected by user



.ssh directory 
directory permissions are drwx------  2 leithner users  4096 Aug 19 15:27 .ssh

leithner@birch:~/.ssh$ ls -l
total 20
-rw------- 1 leithner users  394 Aug 19 14:43 authorized_keys
-rw------- 1 leithner users   26 Aug 19 15:23 config
-rw------- 1 leithner users 1675 Aug 19 15:26 id_rsa
-rw------- 1 leithner users  396 Aug 19 15:26 id_rsa.pub
-rw------- 1 leithner users  888 Aug 19 15:28 known_hosts

.ssh directory on server
directory permissions on server are: drwx------  2 leithner ppa    4096 Aug 19 14:27  .ssh



leithner@elm:~/.ssh$ ls -l
total 20
-rw------- 1 leithner ppa  396 Aug 19 14:27 authorized_keys
-rw------- 1 leithner ppa   85 Aug 19 14:23 config
-rw------- 1 leithner ppa 1823 Aug 19 13:36 id_rsa
-rw------- 1 leithner ppa  394 Aug 19 13:36 id_rsa.pub
-rw------- 1 leithner ppa 1992 Aug 19 14:20 known_hosts

ssh-keygenを使用してキーを生成し、ssh-copy-id leithner@elmを使用してサーバーにコピーしました。

sshはキーを使用する代わりにパスワードを要求します。

 ssh -p 53997 elm
 leithner@elm's password:

これはサーバーのauth.logです。

Aug 22 11:59:03 elm sshd[2081934]: 認証が拒否されました: /home/leithner ディレクトリの無効な所有権またはモードパスワードで許可 43340

自分のディレクトリにどのような権限が必要ですか?

解決済み:問題は、私のホームディレクトリが775で755でなければならないことです。 drwxr-xr-x 24 leithner ppa 4096 8月22日 12:55 leithner

どんなアイデアにも感謝します。キーを何度も書き換えました。

ベストアンサー1

私が考えることができる唯一のこと

  1. 権限(ほとんどは正しいことがわかります)。

    唯一奇妙に見えるのは*.pub鍵でした。確実にするには、chmodフォルダとキーを再度開くことができます。stat --format '%a' <dir or file>数値も提供されますchmod。これにより、フォルダとファイルに対する権限が正しいことを確認できます。

    次の権限(正しい)は、chmodホストとゲストで同じでなければなりません。

chmod 700 $HOME/.ssh
chmod 600 $HOME/.ssh/id_rsa
chmod 644 $HOME/.ssh/id_rsa.pub
chmod 600 $HOME/.ssh/authorized_keys # yes, this one needs specific permissions, too
  1. コピー方法エラー

    あなたがした方法は十分でしょうが。これが機能するには、権限が正しい必要があります。そうしないと、毎回パスワードの入力を求められます。ssh-copy-id -i .ssh/id_rsa.pub [email protected]

このフラグなしでSSH出力を発行してください-v。これにより、私たちは何が起こっているのかをよりよく知ることができます。

おすすめ記事