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

Using Yubikey for sudo over SSH session

· 52CE 我爱测

I currently use Kryptonite to handle protecting the private key I use to SSH into hosts. This works well, except when I need to escalate to root. When I sudo I have to go copy a randomly generated 20-character string out of my pa…

问题原文

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

I currently use Kryptonite to handle protecting the private key I use to SSH into hosts. This works well, except when I need to escalate to root.

When I sudo I have to go copy a randomly generated 20-character string out of my password manager, check that I'm really at the password prompt, and paste it to get my command running.

I'd much rather use my Yubikey to authenticate sudo. I can find 101 guides on how to do this when sudoing on on local hosts with the Yubikey plugged into my local hosts, but how can I do this when I want to sudo on a remote host over SSH with the key plugged into my local machine?

Both local and remote hosts are running recent Linux/GNU distros, specifically RHEL/Fedora if it makes a difference.

已采纳解答

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

There is pam_ssh_agent_auth, which does exactly what you need. This package is available for both Fedora and RHEL so the process of setting up and installing is very straight-forward:

yum install pam_ssh_agent_auth

Add to your /etc/sudoers:

Defaults    env_keep += \"SSH_AUTH_SOCK\"

Put your ssh-public key to /etc/security/authorized_keys (get it from yubikey for example using ssh-keygen -D /usr/lib64/pkcs11/opensc-pkcs11.so)

Add a line to the start of /etc/pam.d/sudo:

auth       sufficient   pam_ssh_agent_auth.so

Then you just add the pkcs11 library to your ssh-agent and you can run sudo without password (authenticating using key on the token):

ssh-add -s /usr/lib64/pkcs11/opensc-pkcs11.so
sudo -i

This process is also described in the manual page for pam_ssh_agent_auth.

Note that the keys on the yubikey needs to be generated before, but this is described in the Yubico documentation already.

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

资料来源与适用范围

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

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

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