为OpenSSH开启双因素认证
source link: https://www.lujun9972.win/blog/2018/03/06/%E4%B8%BAopenssh%E5%BC%80%E5%90%AF%E5%8F%8C%E5%9B%A0%E7%B4%A0%E8%AE%A4%E8%AF%81/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
为OpenSSH开启双因素认证
至OpenSSH 6.2开始,就多了一个配置项 AuthenticationMethods
能够用来实现多因素认证。
该配置项可以指定一个或多个认证方式,只有所有认证方式都通过后才会被认为是认证成功。
比如,要指定账户必须拥有指定的密钥和正确的密码才能登陆,则可以这样配置:
# 不要忘了开启这些认证方式 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"
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK