teketeke_55の日記

技術メモとか

ssh鍵認証ログイン時のホームディレクトリパーミッション制限を緩める

[ssh]

ssh鍵認証でログインする場合、homeディレクトリのパーミッションが所有ユーザー以外に書き込み権限があるとアクセスが拒否される。

# ssh -i hoge_id_rsa hoge@hogehoge
Permission denied (publickey).

ログイン対象機器を確認

# ll /home/
drwxrwx--- 23 hoge      hoge      4096  2月  2 14:29 hoge

ログを見てみる

# less /var/log/secure
sshd[24942]: Authentication refused: bad ownership or modes for directory /home/hoge

これを解除するにはsshd_configでStrictModesをnoに設定する。

# vim /etc/ssh/sshd_config
StrictModes no

マニュアルでは

$ man sshd_config
  StrictModes
   Specifies whether sshd should check file modes and ownership of the user’s files and home directory before accepting login.  This is normally desirable because novices sometimes acci-dentally leave their directory or files world-writable.  The default is “yes”.

とある。
ログイン時にユーザーディレクトリの権限を確認してする機能で、ホームディレクトリを誰でも書き込み可能な状態にして公開してしまうことを防ぐ目的がらしい。
鍵認証時にホームディレクトリのパーミッションを確認してくれなくなるので設定を投入した後の取り扱いは慎重にやろう。