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

Enforcing 2FA configuration on next SSH login for every user

· 52CE 我爱测

I have found numerous tutorials on how to enable 2FA (TOTP, RFC 6238) but is there also a way to force SSH users to configure it on the first login? (I am using OpenSSH server) I guess I could create a script that runs everytime …

问题原文

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

I have found numerous tutorials on how to enable 2FA (TOTP, RFC 6238) but is there also a way to force SSH users to configure it on the first login? (I am using OpenSSH server)

I guess I could create a script that runs everytime and checks whether a .google_authenticator for the particular user exists and if not then runs google-authenticator until it does and then edits /etc/pam.d/sshd (uh-oh), and otherwise runs the default shell/command… but there are perhaps many unforeseen edge cases and possibilities for breaking SSH login.

So before I possibly re-invent the wheel, and do so haphazardly, does an existing solution already exist?

I would have assumed that it does since it's the norm for user-facing software, e.g. Gitlab and Gsuite come to mind, where you can force users to configure 2FA on the next login.

已采纳解答

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

I am not sure if someone already wrote script for general purpose because these things sometime specific to requirement.

What I can suggest is use env files(.bashrc,.bash_profile etc) to alter your ssh/2FA etc file.

Anatomy of script will be like below:

if <check 2fa file setup exists>
    # execute this if found
    # or continue
else
    # setup 2FA and exit for next login.

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

资料来源与适用范围

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

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

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