14

Ubuntu配置SFTP服务用户目录权限

 5 years ago
source link: https://www.linuxprobe.com/ubuntu-set-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.
导读 限制一个Linux用户,让他只能在指定的目录下进行添加、修改、删除操作,并且只能使用sftp登录服务器,不能用ssh操作。用系统自带的internal-sftp。
创建新用户ui,禁止ssh登录

可用使用-M参数,禁止创建个人目录

useradd -s /sbin/nologin xiaobai //xiaobai表示你要创建的新用户
设置用户密码
passwd xiaobai
配置sshd_config
vim /etc/ssh/sshd_config
修改为下面内容,保存退出
#注释掉这行
#Subsystem sftp /usr/libexec/openssh/sftp-server
#添加在配置文件末尾
Subsystem sftp internal-sftp           #指定使用sftp服务使用系统自带的internal-sftp
Match User xiaobai                     #匹配用户,如果要匹配多个组,多个组之间用逗号分割
ChrootDirectory /var/www               #用chroot将指定用户的根目录,有权限要求,看下面注释
ForceCommand internal-sftp             #指定sftp命令

PS:设置目录权限,目录的权限设定有两个需要注意的地方:

目录开始一直往上到系统根目录为止的目录拥有者都只能是root

目录开始一直往上到系统根目录为止都不可以具有群组写入权限

重启sshd服务
service ssh restart      #不知道为什么service sshd restart命令无法使用

后面就是登录测试的过程,如果无法登陆,请注意目录权限设置

修改目录所有者和权限

chmod -R 755 /var/www/html
chown -R xiaobai:xiaobai /var/www/html      #目录随意指定
ChrootDirectory /var/www  这条命令的www目录必须是root权限,www下面的文件夹(或文件)给以用户权限,文中给的是xiaobai权限。
./      root
../     root
html    xiaobai
html2   xiaobai

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK