AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[google-authenticator](server)

Martin Hope
phk
Asked: 2022-01-28 05:27:01 +0800 CST

为每个用户在下次 SSH 登录时强制执行 2FA 配置

  • 1

我找到了许多关于如何启用 2FA(TOTP,RFC 6238)的教程,但是还有一种方法可以强制 SSH 用户在第一次登录时对其进行配置吗?(我正在使用 OpenSSH 服务器)

我想我可以创建一个每次运行的脚本并检查.google_authenticator特定用户的 a 是否存在,如果不存在,则运行google-authenticator直到它存在然后编辑/etc/pam.d/sshd(呃-哦),否则运行默认的 shell/命令......但可能有很多不可预见的边缘情况和破坏 SSH 登录的可能性。

因此,在我可能重新发明轮子并且随意地这样做之前,现有的解决方案是否已经存在?

我会假设它确实如此,因为它是面向用户的软件的规范,例如 Gitlab 和 Gsuite,您可以在其中强制用户在下次登录时配置 2FA。

linux ssh pam google-authenticator two-factor-authentication
  • 1 个回答
  • 165 Views
Martin Hope
Karol
Asked: 2022-01-08 05:14:24 +0800 CST

SSH 认证:(公钥异或密码)+ google 验证码

  • 1

我正在使用 Debian 靶心。我正在尝试设置 SSH 两种类型的登录:

  1. 来自 Google Authenticator 的密码 + 代码(如果用户设置它,“nullok”选项),
  2. 来自 Google Authenticator 的公钥 + 代码(如果用户设置了它,“nullok”选项)。

类型 #1 对我有用。在类型 #2 中,我有来自 GA 的公钥 + 密码(不是公钥密码)+ 代码。我将此行添加到 /etc/ssh/sshd_config

AuthenticationMethods publickey,keyboard-interactive keyboard-interactive

如果提供了密钥,我希望用户不会被提示输入密码。准确地说,如果提供了公钥,如何绕过 pam_unix.so 需求?

有什么办法可以在一台机器上完成我想要的吗?提前致谢。

debian ssh pam google-authenticator two-factor-authentication
  • 1 个回答
  • 104 Views
Martin Hope
Hamish Moffatt
Asked: 2021-08-05 23:28:59 +0800 CST

使用谷歌身份验证器的 SSH 公钥身份验证仍然要求输入密码

  • 4

我正在尝试使用 libpam-google-authenticator 通过 ssh 启用 2FA。并非所有用户都需要启用身份验证器。每个人都使用 ssh 公钥,没有人有密码。我正在运行 Debian buster,并且我还尝试了来自 Bullseye 的 libpam-google-authenticator。

我的问题是,无论我在 PAM 配置中添加什么,没有启用身份验证器的用户永远不会直接登录,而是总是要求输入密码。

我已经安装了 libpam-google-authenticator 并配置了 /etc/ssh/sshd_config :

PasswordAuthentication no
ChallengeResponseAuthentication yes
AuthenticationMethods publickey,keyboard-interactive
PasswordAuthentication no
PermitEmptyPasswords no

我无法计算出正确的 PAM 配置,因此没有 .google_authenticator 文件的用户仍然可以登录。根据我使用的内容,系统会提示用户输入密码(他们没有密码),或者没有完全允许进入。

在 /etc/pam.d/sshd 我尝试过(像这样Trying to get SSH with public key (no password) + google 身份验证器在 Ubuntu 14.04.1 上工作):

#@include common-auth
auth       required     pam_google_authenticator.so debug nullok

在这种情况下,没有验证器设置的用户会被以下调试拒绝;

Aug 05 15:11:18 <host> sshd(pam_google_authenticator)[746624]: debug: start of google_authenticator for "<user>"
Aug 05 15:11:18 <host> sshd(pam_google_authenticator)[746624]: debug: end of google_authenticator for "<user>" Result: The return value should be ignored by PAM dispatch
Aug 05 15:11:18 <host> sshd[746620]: error: PAM: Permission denied for <user> from <IP>

是否pam_permit需要设置后备案例?

我也尝试过之前和之后的各种组合,auth required但auth sufficient它们@include common-auth都会导致没有验证器的用户被要求输入密码,有时也会要求有验证器的用户输入密码。

有没有人有做这个工作的食谱?

debian pam google-authenticator two-factor
  • 2 个回答
  • 1093 Views
Martin Hope
user1709076
Asked: 2020-10-03 11:22:04 +0800 CST

Ubuntu 20.04 中的 sshd_config 更改

  • 0

我注意到在 Ubuntu 20.04 的/etc/ssh/sshd_config中似乎在 sshd_config 的第一行引入了新行。上面写着:

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

这条线是干什么用的?

我还注意到谷歌身份验证器 TOTP 对我不起作用(从某种意义上说,我得到提示并正确输入代码,但仍然不允许登录)除非我删除了这一行。在这种情况下, sshd_config 看起来与它在 Ubuntu 18.04 中的表现完全相同

这与第一行的工作有关吗?

ssh ubuntu-20.04 google-authenticator
  • 1 个回答
  • 1580 Views
Martin Hope
Joum
Asked: 2016-12-28 05:01:57 +0800 CST

如果用户破坏了 bashrc 命令,则注销用户

  • 1

当用户通过 SSH 访问我的 Linux 主机时,我正在运行一个小脚本。此脚本应为用户验证和/或设置 Google Authenticator MFA 访问权限。

现在它按预期工作,但有一个警告 - 在 MFA 配置过程中的任何时候,如果用户 (ie) CTRL+C的,设置向导被中断,但 SSH 会话继续。我需要它来注销试图访问的用户。

我怎样才能做到这一点?

这是我在.bashrc文件底部添加的内容(请注意,这对我来说很新,并且我愿意接受对我当前尝试的批评/改进)。

# MFA validation/configuration

if [[ -n $SSH_CONNECTION ]] ; then
        echo "SSH connection to remote host successful."
        echo "testing if MFA is configured..."

        # is this test enough?
        file="$HOME/.google_authenticator"

        if [ -f "$file" ] ; then
                printf "MFA configured, you may proceed.\n"
        else
                printf "MFA not configured; running setup wizard.\n"

                # the command runs, but the else bit is never reached
                if google-authenticator ; then
                        # I reach this point if I go to the end of the wizard
                        echo "MFA setup successful"
                else
                        # this point is never reached
                        echo "MFA setup failed - logging you out"
                        exit
                fi
        fi
fi
ssh bashrc google-authenticator
  • 1 个回答
  • 253 Views
Martin Hope
PhysiOS
Asked: 2016-08-29 17:53:00 +0800 CST

SSH Google Authenticator 忽略/白名单 ip

  • 3

我安装了 google 身份验证器(两步验证)、“libpam-google-authenticator”包,尽管它要求为每个 SSH 连接提供代码。我想将 localhost 和我自己的 ip 从 google 身份验证器列入白名单,所以我和 localhost 跳过两步验证

或者有没有办法跳过某些 ips 的 SSH 挑战?

google-authenticator
  • 1 个回答
  • 5004 Views
Martin Hope
Itai Ganot
Asked: 2016-06-15 00:28:08 +0800 CST

如何配置 pam sshd 以允许不同用户/组的不同规则?

  • 2

我正在我工作的公司的出站服务器上配置谷歌双重身份验证。

以下是相关配置 /etc/ssh/sshd_config:

ubuntu@stage-itai-1:~$ egrep -v '^#' /etc/ssh/sshd_config  | sed '/^\s*$/d'
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
UsePrivilegeSeparation yes
KeyRegenerationInterval 3600
ServerKeyBits 1024
SyslogFacility AUTH
LogLevel INFO
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
IgnoreRhosts yes
RhostsRSAAuthentication no
HostbasedAuthentication no
PermitEmptyPasswords no
ChallengeResponseAuthentication yes
PasswordAuthentication no
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
UsePAM yes
Match Group gauth
    AuthenticationMethods publickey,keyboard-interactive

/etc/pam.d/sshd:

ubuntu@stage-itai-1:~$ egrep -v '^#' /etc/pam.d/sshd  | sed '/^\s*$/d'
auth required pam_google_authenticator.so nullok
account    required     pam_nologin.so
@include common-account
session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so close
session    required     pam_loginuid.so
session    optional     pam_keyinit.so force revoke
@include common-session
session    optional     pam_motd.so  motd=/run/motd.dynamic noupdate
session    optional     pam_motd.so # [1]
session    optional     pam_mail.so standard noenv # [1]
session    required     pam_limits.so
session    required     pam_env.so # [1]
session    required     pam_env.so user_readenv=1 envfile=/etc/default/locale
session [success=ok ignore=ignore module_unknown=ignore default=bad]        pam_selinux.so open
@include common-password

作为“gauth”组成员的用户应该被强制提供公钥和谷歌验证码,这是预期的和有效的。

不是“gauth”组成员的用户应该被强制提供公钥,但实际上他们可以在不提供公钥或密码的情况下连接到机器。

机器上有一个称为“救援”的特殊用户,该用户应该被强制只提供密码,其目的是永远不会被锁定在机器之外,但实际上用户可以在没有密码的情况下连接密码。

我的问题是,我如何执行我的“假定”规则,这意味着:

  • “gauth”组的用户必须同时提供公钥和 Google OTP
  • 不是“gauth”组成员的用户只能通过提供公钥登录。
  • 用户“rescue”应该只能通过提供密码(或同时提供公钥)登录。

怎么做到呢?

编辑#1:

按照 FaCe 的回答,我的配置/etc/ssh/sshd_config如下:

对于整个文件,我已将 PasswordAuthentication 改回“是”,将“ChallengeResponseAuthentication”改回“否”,然后在文件底部添加以下行:

Match Group guath
    PasswordAuthentication no
    ChallengeResponseAuthentication yes
    AuthenticationMethods publickey,keyboard-interactive
Match User rescue
    PasswordAuthentication yes
    ChallengeResponseAuthentication no
    AuthenticationMethods password

重置 ssh 服务后我无法登录,无论我使用哪个用户,我都会收到以下错误:

ssh_exchange_identification: Connection closed by remote host

并且没有任何内容显示在/var/log/auth.log.

任何人都可以对此事有所了解吗?

authentication ssh pam google-authenticator
  • 2 个回答
  • 5907 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve