linux sftp 远程连接配置
1.配置sshd
编辑/etc/ssh/sshd_config文件(一般放置在此处)
在sshd_config文件中添加如下几行
Subsystem sftp internal-sftp
Match Group sftp #这里是配置用户组,也可以只配置用户(Match User xxxx)
ChrootDirectory /usr/share/test #这里配置只能访问的指定目录
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
2.指定目录 /usr/share/test
/usr/share/test 的所属组和所属主都必须是root (包括usr,share/test),且权限是755权限,不能是777权限
3.创建用户组和用户
groupadd sftp
useradd -s /bin/nologin -d /usr/share/test -g sftp mysftp
echo "123456" | passwd --stdin mysftp
4.重启sshd
systemctl restart sshd
5.意外报错
Job for sshd.service failed because the control process exited with error code. See "systemctl status sshd.service" and "journalctl -xe" for details.
6.查找问题
sshd -t
结果显示:/etc/ssh/sshd_config line 149: Directive ‘UseDNS’ is not allowed within a Match block
7.问题解决
将
Subsystem sftp internal-sftp
Match Group sftp
ChrootDirectory /usr/share/test
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
放在
UseDNS no
之后