大网数据广告活动
服务器运维问答

SSH with key pair and password at same time

· 52CE 我爱测

Is it possible to enable ssh to use both key pair and password at the same time, so the client need the key file and also know the password ? In order that having only one wouldn't work. I don't to have a 2 step authentication us…

问题原文

原帖链接 · Adonist · CC BY-SA 3.0

Is it possible to enable ssh to use both key pair and password at the same time, so the client need the key file and also know the password ? In order that having only one wouldn't work.

I don't to have a 2 step authentication using radius or anything. Just want to improve a bit the security.

Thanks

已采纳解答

原帖链接 · JayMcTee · CC BY-SA 3.0

From https://security.stackexchange.com/questions/17931/possible-to-use-both-private-key-and-password-authentication-for-ssh-login

Now on RHEL / CentOS 7, and any system with a recent version of OpenSSH, you can use:

AuthenticationMethods "publickey,password" "publickey,keyboard-interactive"

Also see: https://lwn.net/Articles/544640/

It is also important to note that the AuthenticationMethods feature applies only to the SSH 2 protocol, and that each authentication method listed must also be explicitly enabled in the sshd_config file.

And a great explanation in detail here:

https://sysconfig.org.uk/two-factor-authentication-with-ssh.html

Match User johndoe
AuthenticationMethods publickey,keyboard-interactive

Read the commas as logical AND. On login, johndoe's key pair will be checked first and if it's a match, you'll see this:

Authenticated with partial success.

Then, he will be asked for his password. So without realising, you have just set up MFA. Your key pair being what you have, the account password being what you know. This is possibly the simplest way of setting up MFA with SSH, and already better than single-factor authentication.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-08-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。