書き込み権限を持つ特定のディレクトリにSSHユーザーを制限する方法は?

書き込み権限を持つ特定のディレクトリにSSHユーザーを制限する方法は?

次の設定を使用してsshユーザーを特定のフォルダに正常に制限しましたが、グループの権限を読み取り/書き込みに変更すると、ユーザーはサーバーにログインできません。

/etc/passwd私が変わった後

/bin/bashユーザー/bin/false

/etc/ssh/sshd_config追加する前に

Subsystem sftp internal-sftp
    Match Group dnduser
    ChrootDirectory /home/dnduser
    ForceCommand internal-sftp
    AllowAgentForwarding no
    AllowTcpForwarding no
    X11Forwarding no

作業/home/dnduserディレクトリ権限には書き込み権限がありません。

#chmod 755 /home/dnduser -R

#chown root:dnduser /home/dnduser -R

権限を次に変更すると

#chmod 775 /home/dnduser -R

ユーザーがログインできません

ベストアンサー1

再帰的なchmodは危険であり、ディレクトリとファイルのモードを同じに変更するので避けるべきです。ファイルは通常実行ビットを必要とせず、Ulrichが指摘したように、$ HOMEの一部のファイルはグループ化または読み取ることができません。 /書き込み可能。

修理損傷:

find /home/dnduser -type f -exec chmod 640 {} \;
find /home/dnduser -type d -exec chmod 750 {} \;

2番目man sshd_configの文は最も関連性があります。

 ChrootDirectory
         Specifies the pathname of a directory to chroot(2) to after authentication.  At session startup sshd(8) checks that all components of the
         pathname are root-owned directories which are not writable by any other user or group.  After the chroot, sshd(8) changes the working direc‐
         tory to the user's home directory.  Arguments to ChrootDirectory accept the tokens described in the TOKENS section.

デバッグを支援するために、"ssh -vvv"を使用してhyperverboseモードでsshを実行し、サーバー側(RHベースのシステムの場合)で/​​var/log/secureおよび/var/log/messagesのログ出力を表示できます。 。サーバーログ出力で次に調査する場所へのポインタを取得する必要がありますが、マニュアルページでは...問題の原因を指しているようです...。

おすすめ記事