Linux 添加Match User 重启sshd出现job for ssh.service failed

最近在做一个sftp的需求,需要添加一个sftp用户来传输文件到linux的指定路径,通过网络学习,需要新增一个ftp账户,需要在/etc/ssh/sshd_config中新增几条命令:

Subsystem sftp internal-sftp
Match User root  // 匹配用户,用户为root时才做处理
ChrootDirectory /srv/ftp // 设置用户sftp访问的根目录
AllowTcpForwarding yes // 允许ssh访问设置为yes,不允许ssh访问,设置为no

修改完sshd_config后,运行下面命令重启sshd,则出现如下错误:
在这里插入图片描述
通过百度搜索,找到查询运行错误的命令:

root@localhost:~# /usr/sbin/sshd  -T
/etc/ssh/sshd_config line 92: Directive 'UsePAM' is not allowed within a Match block
root@localhost:~#

原来是UsePAM 跟Match User 相互冲突,造成这种问题的原因是添加的Match位置不对,将Match添加到 UsePAM后面,
在这里插入图片描述

root@localhost:~#
root@localhost:~# service sshd restart
root@localhost:~#

没有报错,看来是成功了。远程sftp连接尝试一波,连接成功。

C:\Users\xxxxxx>sftp root@192.168.xxx.xxx
root@192.168.xxx.xxx's password:
Connected to root@192.168.xxx.xxx.
sftp>
sftp>

什么是UsePAM?
PAM 代表可插入身份验证模块(Pluggable Authentication Modules)。这些模块提供额外的身份验证规则,保护对计算机的访问。
详细信息可以看下面的连接:
保护 SSH 的三把锁

猜你喜欢

转载自blog.csdn.net/PRML_MAN/article/details/114254590