Aeroshell 客户端如何利用 双因子认证(2FA)登录 SSH

简介: 本文介绍如何在Linux中集成SSH与Google Authenticator,实现密码+TOTP动态验证码的双因子认证(2FA),有效防范暴力破解、密钥泄露等风险,满足零信任与合规要求,且兼容现有运维流程。

背景与问题分析

在传统的服务器远程访问场景中,SSH(Secure Shell)作为最常用的安全协议之一,被广泛应用于 Linux 系统管理与自动化运维中。
然而,默认的 SSH 登录机制通常仅依赖账户密码或公钥进行身份认证,这种单一认证方式在实际生产环境中已逐渐暴露出安全隐患——一旦密码被暴力破解、钓鱼窃取或公钥文件泄露,攻击者便可直接获得系统访问权限。

随着企业安全合规和零信任架构理念的普及,多因素认证(Multi-Factor Authentication, MFA) 成为了提升系统访问安全的重要手段。
本文将介绍如何在 Linux 环境中,通过整合 SSH 与 Google Authenticator(基于 TOTP 的一次性动态密码算法),构建一种基于 账户密码 + 动态验证码(OTP) 的双因子登录机制,从而在不影响运维效率的前提下,大幅提升远程访问的安全防护能力。

密码泄露风险
用户往往重复使用弱密码或相同密码,容易被撞库、暴力破解或钓鱼攻击获取。

密钥泄露与滥用
公钥登录虽然避免了密码暴力破解,但私钥一旦泄露,攻击者仍可无感登录。

缺乏登录行为确认机制
单因素认证无法区分合法用户与被盗凭证的攻击者,缺乏实时验证手段。

合规与审计需求上升
在金融、医疗及政企场景中,安全审计与访问追溯要求越来越严格,传统 SSH 已无法满足双重身份验证要求。

为此,引入 基于 TOTP(Time-based One-Time Password)的一次性验证码机制,可在用户输入密码后,要求额外输入手机端动态验证码,形成 “你知道的(密码) + 你拥有的(设备)” 的双因子安全体系。
这种方式既能与现有 SSH 体系无缝兼容,又能满足安全合规和运维便利性的平衡。

安装Google Authenticator

# Debian / Ubuntu
sudo apt update
sudo apt install libpam-google-authenticator
##由于验证码是基于时间动态生成,所以务必设置ntp服务。
sudo apt install ntpdate -y
sudo ntpdate time.google.com
date
# CentOS / RHEL / Rocky / Alma
sudo yum install google-authenticator -y
sudo yum install ntpdate -y
sudo ntpdate time.google.com
###为当前用户生成密钥
google-authenticator
###会询问如下问题:
Do you want authentication tokens to be time-based (y/n)  → y
Do you want me to update your "/home/xxx/.google_authenticator" file (y/n) → y
Do you want to disallow multiple uses of the same token (y/n) → y
Do you want to increase the default window from 30s to 60s (y/n) → n
Do you want to enable rate-limiting (y/n) → y

安装过程会提示如下的一串key,保存它。

image.png

服务端配置修改

/etc/pam.d/sshd

# PAM configuration for the Secure Shell service
# Standard Un*x authentication.
@include common-auth


# ✅ 新增:Google Authenticator 验证模块
auth required pam_google_authenticator.so
# ✅ 新增:Google Authenticator 验证模块

# Disallow non-root logins when /etc/nologin exists.
account    required     pam_nologin.so

# Uncomment and edit /etc/security/access.conf if you need to set complex
# access limits that are hard to express in sshd_config.
# account  required     pam_access.so

# Standard Un*x authorization.
@include common-account

# SELinux needs to be the first session rule.  This ensures that any
# lingering context has been cleared.  Without this it is possible that a
# module could execute code in the wrong domain.
session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so close

# Set the loginuid process attribute.
session    required     pam_loginuid.so

# Create a new session keyring.
session    optional     pam_keyinit.so force revoke

# Standard Un*x session setup and teardown.
@include common-session

# Print the message of the day upon successful login.
# This includes a dynamically generated part from /run/motd.dynamic
# and a static (admin-editable) part from /etc/motd.
session    optional     pam_motd.so  motd=/run/motd.dynamic
session    optional     pam_motd.so noupdate

# Print the status of the user's mailbox upon successful login.
session    optional     pam_mail.so standard noenv # [1]

# Set up user limits from /etc/security/limits.conf.
session    required     pam_limits.so

# Read environment variables from /etc/environment and
# /etc/security/pam_env.conf.
session    required     pam_env.so # [1]
# In Debian 4.0 (etch), locale-related environment variables were moved to
# /etc/default/locale, so read that as well.
session    required     pam_env.so user_readenv=1 envfile=/etc/default/locale

# SELinux needs to intervene at login time to ensure that the process starts
# in the proper default security context.  Only sessions which are intended
# to run in the user's context should be run after this.
session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so open

# Standard Un*x password updating.
@include common-password

具体内容参考 如下两个配置,携带✅标记的参数就是默认配置中变动的内容。

/etc/ssh/sshd_config配置


# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/bin:/usr/games

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Include /etc/ssh/sshd_config.d/*.conf

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)

# ✅ 新增:开启keyboard交互式认证
KbdInteractiveAuthentication yes
#✅ 新增:开启keyboard交互式认证

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the KbdInteractiveAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via KbdInteractiveAuthentication may bypass
# the setting of "PermitRootLogin prohibit-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and KbdInteractiveAuthentication to 'no'.
UsePAM yes

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server


#AuthenticationMethods  keyboard-interactive
## ✅新增:开启认证方式
AuthenticationMethods password keyboard-interactive

aeroshell客户端

点击添加SSH主机

image.png

选择多因子认证,勾选密码+OTP认证。填入刚刚Google Authenticator的OTP 密钥。其他正常填写即可,保存。

image.png

结束语

至此,我们完成了基于 Linux SSH + Google Authenticator + Aeroshell 的 双因子认证(2FA)登录方案。
通过结合账户密码与一次性动态验证码(OTP),Aeroshell 为服务器远程登录提供了更安全、可视化的多因素认证方式。
这种集成不仅能有效防御暴力破解与密码泄露风险,还能兼容公钥登录场景,帮助运维人员在 Linux、Ubuntu、CentOS 等系统中快速部署安全的 SSH 登录环境。
借助 Aeroshell 智能终端客户端 的图形化配置界面与 2FA 支持,用户无需复杂命令即可轻松启用 MFA 安全登录,让服务器访问更加高效、安全、智能。

目录
相关文章
|
19天前
|
人工智能 自然语言处理 监控
OpenClaw“养龙虾”保姆级教程:从零基础部署到进阶玩法与安全避坑指南
2026年,一款名为OpenClaw的开源AI智能体迅速走红全网,凭借红色龙虾样式的标识,被爱好者亲切称作“龙虾”,而部署、调教与使用OpenClaw的全过程,也被大家戏称为“养龙虾”。OpenClaw的核心理念是打造真正能落地执行任务的AI,它打破了传统AI仅停留在对话交互的局限,通过赋予模型操作系统、操控软件、读写文件、控制浏览器、执行代码等真实操作权限,让AI从“聊天助手”升级为可以自主干活的数字员工,能够理解自然语言指令并独立完成一系列自动化工作流。
524 7
|
18天前
|
运维 Ubuntu Linux
Linux 多发行版 远程桌面踩坑总结:Deepin / openKylin / Ubuntu 实战记录
本文详述TigerVNC在Ubuntu 26.04、Deepin 20.9/23.9及openKylin 2.0 SP2四大发行版的适配实践,重点解决Wayland/X11冲突、DBus、输入法、DDE兼容等痛点,最终推荐「deepin」为最稳定方案。(239字)
292 4
|
2月前
|
人工智能 JSON 供应链
畅用7个月无影 JVS Claw |手把手教你把JVS改造成「科研与产业地理情报可视化大师」
LucianaiB分享零成本畅用JVS Claw教程(学生认证享7个月使用权),并开源GeoMind项目——将JVS改造为科研与产业地理情报可视化AI助手,支持飞书文档解析、地理编码与腾讯地图可视化,助力产业关系图谱构建。
23684 15
畅用7个月无影 JVS Claw |手把手教你把JVS改造成「科研与产业地理情报可视化大师」
|
19天前
|
数据可视化 Linux Docker
Hermes Agent可视化面板部署指南:Docker一键搭建WebUI全平台教程(Windows+Linux通用)
Hermes Agent作为一款自主进化型AI智能体,凭借持久记忆、任务沉淀、多工具并行等能力,成为开发者与办公用户的高效助手。但原生命令行操作对新手不够友好,复杂指令记忆成本高,可视化管理需求日益强烈。Hermes WebUI的出现彻底解决了这一问题,通过图形化界面即可完成模型配置、任务管理、文件操作、对话交互、定时任务等全部功能,大幅降低使用门槛。
1077 9
|
19天前
|
人工智能 运维
Agentic Ops 企业级可观测性运维智能体实战研讨会,邀您5月29日北京见!
阿里云将于5月29日在北京阿里巴巴朝阳科技园举办【Agentic Ops已来:企业级可观测性运维智能体实战】技术沙龙,聚焦企业级可观测性运维智能体实战。扫码或点击链接立即报名!
|
25天前
|
弹性计算 人工智能 缓存
阿里云轻量应用服务器2核2G38元、2核4G9.9元起:配置解析、适用场景与选购指南
2026年阿里云轻量应用服务器抢购活动提供两大核心配置:2核2G(200M峰值带宽+40G ESSD盘)抢购价38元/年,适合个人建站与入门学习;2核4G(200M带宽+50G ESSD盘)9.9元/月或199元/年,支持OpenClaw镜像一键部署AI助理。抢购每日10:00和15:00限时开抢,仅限新用户。本文同时对比了ECS 99计划(e实例99元/年、u1实例199元/年,新购续费同价至2027年3月),建议用户根据业务规模、AI需求及长期成本综合选型。
374 14
|
19天前
|
运维 网络协议
KKCE 在线 Ping|实用网络连通性检测小工具
KKCE在线Ping是一款免安装、浏览器直用的网络检测工具,支持多节点同步测试域名/IP连通性、延迟与丢包率,直观定位卡顿、访问异常等基础网络问题,兼顾个人排查与运维需求。(239字)
370 1
|
2月前
|
存储 人工智能 安全
深度解析 OpenClaw 在 Prompt / Context / Harness 三个维度中的设计哲学与实践
本文的核心思路是从Prompt、Context和Harness这三个维度展开,分析OpenClaw的设计思路,提炼出其中可复用的方法论,来思考如何将这些精华的设计哲学应用到我们自己的Agent系统设计和业务落地中去。(文章内容基于作者个人技术实践与独立思考,旨在分享经验,仅代表个人观点。)
1792 38
深度解析 OpenClaw 在 Prompt / Context / Harness 三个维度中的设计哲学与实践
|
2月前
|
人工智能 监控 Kubernetes
LoongCollector + ACS Agent Sandbox:构建 AI Agent 生产级运行平台
文章介绍了阿里云ACSAgentSandbox与LoongCollector协同构建的AIAgent生产级运行平台,通过沙箱隔离保障运行时安全,并以高性能、全链路可观测能力解决Agent行为不可预测和执行风险难题。
840 36