日々精進

新しく学んだことを書き留めていきます

sshでログイン出来ない問題

SSHは何度もハマってるが、またやってしまった。。

  • dockerコンテナ内でrootユーザがsshdを起動
  • /root/.ssh/authorized_keys に正しいキーは登録済み。権限も正しく設定済

上記の状況で、秘密鍵でログインできないがパスワードではログイン出来た。ログは以下。

debug1: Next authentication method: publickey 
debug1: Offering RSA public key: /Users/*/.ssh/*.pem 
debug3: send_pubkey_test 
debug3: send packet: type 50 
debug2: we sent a publickey packet, wait for reply 
debug3: receive packet: type 51 
debug1: Authentications that can continue: publickey 
debug1: Trying private key: /Users/*/.ssh/*.pem 
debug3: sign_and_send_pubkey: RSA SHA256:2xNV3Rf1hRTUpr5+FscZQSeGN77fxSjDr/IvxtD/FNQ 
debug3: send packet: type 50 
debug2: we sent a publickey packet, wait for reply 
debug3: receive packet: type 51 
debug1: Authentications that can continue: publickey 
debug2: we did not send a packet, disable method 
debug1: No more authentication methods to try. 
Permission denied (publickey).

原因はauthorized_keys の場所がまずかったこと。 rootユーザがsshdを起動するので/root/.ssh下に置くと思っていたが/home/user/.ssh/authorized_keysが正しかった。 そりゃログイン先のユーザ毎に許可するauthorized_keysを置かないと、ユーザ毎にログイン出来る人を分けたりできないよな。。