导读 从 OpenSSH 6.2 开始已经支持 SSH 多因素认证,本文就来讲讲如何在 OpenSSH 下启用该特性。

OpenSSH 6.2 以后的版本多了一个配置项 AuthenticationMethods。该配置项可以让 OpenSSH 同时指定一个或多个认证方式,只有所有认证方式都通过后才会被认为是认证成功。

比如:要指定账户必须同时拥有指定的密钥和正确的密码才能登陆,则可以这样配置。

# 不要忘记开启这些认证方式  
PubkeyAuthentication yes  
PasswordAuthentication yes  
AuthenticationMethods publickey,password 

注:多个认证方式之间用 , 分隔开来。

你也可以设置多组多因素认证,只要每组认证用空格分隔开就行。

比如:你要设置登陆用户必须有合适的密钥,然后若是用户来自于授信主机,则让他直接登陆,否则还需要输入密码才能登陆。我们可以类似下面这样配置:

AuthenticationMethods publickey,password publickey,hostbased

开启多因素认证有一个不好的地方就是对自动化脚本很不友好。因此一般来说多因素认证会跟 Match User 或 Match Group 一起连用,用来限制某些用户开启或者不开启双因素认证。

比如:一个比较常见的场景可能就是为有管理权限的用户设置多因素认证。

PubkeyAuthentication yes  
PasswordAuthentication yes  
Match Group wheel  
AuthenticationMethods publickey,password 

当然,你也可以为一般用户都开启多因素认证,但提供某些密钥认证的用户来给自动化脚本使用。

AuthenticationMethods publickey,password
Match User git
AuthenticationMethods publickey
ForceCommand /usr/bin/git-shell -c "$SSH_ORIGINAL_COMMAND"

原文来自:https://mp.weixin.qq.com/s/Dpqe3yn9rsZHvvUjBiVWKA

本文地址:https://www.linuxprobe.com/two-steps-ssh-security.html编辑:J+1,审核员:逄增宝

Linux命令大全:https://www.linuxcool.com/

Linux系统大全:https://www.linuxdown.com/

红帽认证RHCE考试心得:https://www.rhce.net/