72

如何在Linux下进行SFTP用户权限设置

 6 years ago
source link: https://www.linuxprobe.com/linux-sftp.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
导读  你的openssh-server版本至少得失4.8p1, 因为配置权限需要版本添加的新配置项ChrootDirectory来完成。如何查看自己服务器上的ssh版本?大家可以尝试以下命令:$ ssh -V

具体实施步骤:

1. 我们需要创建一个用户组,专门用于sftp用户
$ groupadd sftpusers
2. 我们创建一个用户test
$ useradd -s /bin/false -G sftpuser test

注意这里我们将test用户的shell设置为/bin/false使他没有登陆shell的权限

3. 编辑 /etc/ssh/sshd_config

找到Subsystem这个配置项,将其修改为

Subsystem sftp internal-sftp

然后再到文件最尾处增加配置设定属于用户组sftpusers的用户都只能访问他们自己的home文件夹

Match Group sftpusers

ChrootDirectory %h

ForceCommand internal-sftp

AllowTcpForwarding no

保存并关闭文件

4. 修改test用户home文件夹的权限,让其属于root用户
chown root ~test
5. 重启sshd服务
$ service sshd restart
6. 测试用户账号
$ ssh test@localhost

连接会被拒绝或者无法登陆

$ sftp tesst@localhost

登陆后你会发现你的账号无法切换到除自己home目录之外的地方的

常见问题:

如果你链接服务器的时候出现下面的提示:

Write failed: Broken pipe

Couldn't read packet: Connection reset by peer

这个问题的原因是ChrootDirectory的权限问题,你设定的目录必须是root用户所有,否则就会出现问题。所以请确保sftp用户根目录的所有人是root, 权限是 750 或者 755。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK