配置sftp
作者:bin应用场景:添加某些用户仅用于sftp登录,进行文件操作, 并且不能使用ssh进行登陆
需要注意OpenSSH的版本,需要4.8p1以上
1、我们先新建一个用户
useradd ftptest -d /home/ftptest
设置密码
passwd ftptest
2、配置sshd文件
vim /etc/ssh/sshd_config
添加下面代码
Subsystem sftp internal-sftp
并且注释,因为只能有一处声明
#Subsystem sftp /usr/libexec/openssh/sftp-server
然后添加限制用户
Match User ftptest ChrootDirectory /home/ftptest X11Forwarding no AllowTcpForwarding no ForceCommand internal-sftp
解释
ChrootDirectory 可访问的根目录
X11Forwarding no 不允许 SSH的X 转发
AllowTcpForwarding no 不允许TCP转发
ForceCommand 强制使用internal-
sftp
3、配置ftp根目录权限
用户的根目录必须是 750,并且用户和用户组为 root:ftptest ,否则登录会显示软件错误
drwxr-x--- 5 root ftptest 4096 May 27 11:49 /home/ftptest
在/home/ftptest/下创建work目录,并且指定用户组为 ftptest:ftptest,让ftptest所有操作在work下进行
因为/home/ftptest是没有写权限的,而/home/ftptest/work/ 是有读写权限。
drwxr-x--- 5 ftptest ftptest 4096 May 27 11:49 /home/ftptest/work/
最后/home/ftptest的上级目录必须是root所属,并且权限为755