创建用户组
groupadd sftp
创建用户test

useradd -G sftp -s /sbin/nologin test
-s 禁止用户ssh登录
-G 加入sftp用户组

创建密码
passwd test
修改配置文件 sshd_config

sudo vim /etc/ssh/sshd_config

将下面这行注释
#Subsystem  sftp  /usr/libexec/openssh/sftp-server

然后在末行加入:
Match Group sftp #匹配sftp用户组中的用户
X11Forwarding no 
AllowTcpForwarding no
ChrootDirectory %h #只能访问默认的用户目录(自己的目录), 例如 /home/wwwroot
ForceCommand internal-sftp

设置目录权限

chown root:sftp /home/wwwroot
chgrp -R sftp /home/wwwroot
chmod -R 755 /home/wwwroot
# 设置用户可以上传的目录, 该用户下允许用户上传删除修改文件及文件夹
mkdir /home/wwwroot/upload
chown -R test:sftp /home/wwwroot/upload
chmod -R 755 /home/wwwroot/upload

相关文章:

  • 2022-12-23
  • 2021-04-03
  • 2022-01-13
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2021-07-31
猜你喜欢
  • 2022-12-23
  • 2021-08-15
  • 2021-11-06
  • 2021-05-17
  • 2021-09-03
相关资源
相似解决方案