無慈悲なPermission denied (publickey)
リモートからrsync
するのにwww-data権限で書き込まないと色々都合が悪いので、
$ mkdir /var/www/.ssh/
$ cp ~/.ssh/authorized_keys /var/www/.ssh/
$ chmod -R 700 /var/www/.ssh/
$ chown -R www-data:www-data /var/www/.ssh/
とやって他のユーザーの鍵をコピってwww-dataでもログインできる設定にしました。
で、いざログインしようとしたら、
$ ssh -l www-data gmo
Permission denied (publickey).
無慈悲なPermission denied。
デバッグ情報を出す
-v
をいくつか入れるとだんだん饒舌になったはず。
$ ssh -l www-data gmo -vvvv
...
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/hentai-kun/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
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).
うん、さっぱりわからん。
サーバー側のログを見る
$ sudo less /var/log/auth.log
...
Jun 21 18:48:48 sub0000526857 sshd[29849]: Authentication refused: bad ownership or modes for directory /var/www
Jun 21 18:48:48 sub0000526857 sshd[29849]: Connection closed by ***.***.***.*** [preauth]
お、所有者か権限がおかしいんじゃね?って言ってる。
で、結局
drwxrwxr-x 6 www-data www-data 4096 Jun 21 19:58 www/
www-dataのホームディレクトリが775だったのを、
drwxr-xr-x 6 www-data www-data 4096 Jun 21 19:58 www/
755に変更したら動きました。
ホームディレクトリがグループ権限で操作できるとホームディレクトリごと入れ替えられるリスクがあるから禁止にしているのかなぁ?