
本文将指导您如何在Linux系统中为SFTP用户设置权限,确保安全访问。
<code class="bash">$ groupadd sftpusers</code>
<code class="bash">$ useradd -s /bin/false -G sftpusers test</code>
<code>Subsystem sftp internal-sftp</code>
在文件末尾添加以下配置,限制sftpusers组的用户只能访问其主目录:
<code>Match Group sftpusers
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no</code>
保存并关闭文件。
<code class="bash">chown root ~test</code>
<code class="bash">$ systemctl restart sshd</code>
<code class="bash">$ sftp test@localhost</code>
您应该只能访问test用户的主目录。 尝试使用SSH登录将会被拒绝。
常见问题排查:
如果连接时出现“Write failed: Broken pipe”或“Couldn't read packet: Connection reset by peer”错误,这通常是由于ChrootDirectory权限问题导致的。 请确保SFTP用户主目录的所有者为root,权限设置为750或755。










