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

Using 2 key pairs simultaneously for ssh authentication

· 52CE 我爱测

I have a ssh server running on a raspberry pi. This ssh server can only be accessed by 1 user on my ubuntu laptop only. I have created 2 pairs of ssh keys using: ssh-keygen -t ed25519 -o -a 100 ssh-keygen -t rsa -b 4096 -o -a 100…

问题原文

原帖链接 · iLW · CC BY-SA 4.0

I have a ssh server running on a raspberry pi. This ssh server can only be accessed by 1 user on my ubuntu laptop only.

I have created 2 pairs of ssh keys using:

ssh-keygen -t ed25519 -o -a 100 
ssh-keygen -t rsa -b 4096 -o -a 100

The 2 public keys have been appended to ~/.ssh/authorized_keys on the ssh server.

When I view the authorized_keys file, it is as below:

ssh-ed25519 ...
ssh-rsa ...

What I want is a dual authentication where BOTH key pairs are verified before establishing ssh connection. In my case, I have noticed that it is possible to connect whenever I have 1 key pair authenticated.

Kindly assist.

社区高分解答

原帖链接 · A.B · CC BY-SA 4.0

Yes you can configure your server to require multiplie public keys, as documented in the AuthenticationMethods sshd_config keyword:

If the publickey method is listed more than once, sshd(8) verifies that keys that have been used successfully are not reused for subsequent authentications. For example, “publickey,publickey” requires successful authentication using two different public keys.

So to test this on a single user named test, one can add this at the end of the sshd_config file (and reload configuration):

Match User test
    AuthenticationMethods publickey,publickey

And then add the two public keys in ~test/.ssh/authorized_keys as usual.

On the client side, if keys aren't readily available for example with a running ssh-agent one should supply both keys as parameters like for example:

ssh -i ~/.ssh/id_rsa -i ~/.ssh/id_ed25519 test@server

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

资料来源与适用范围

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

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

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