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 / 问题 / 822853
Accepted
Joum
Joum
Asked: 2016-12-28 05:01:57 +0800 CST2016-12-28 05:01:57 +0800 CST 2016-12-28 05:01:57 +0800 CST

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

  • 772

当用户通过 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 1 个回答
  • 253 Views

1 个回答

  • Voted
  1. Best Answer
    Slipeer
    2016-12-28T05:12:53+08:002016-12-28T05:12:53+08:00

    您可以添加行

    trap '' 2
    

    在脚本开始时禁用CTRL+C和

    trap 2
    

    最终启用CTRL+C功能。

    这将防止用户阻止您的脚本执行。

    请注意,这应该添加到 /etc/bashrc 中,使其成为系统范围且用户不可修改

    https://www.cyberciti.biz/faq/unix-linux-shell-scripting-disable-controlc/

    • 3

相关问题

  • 如何最好地设置 ssh 隧道以访问远程网络 (Linux)

  • SSH 和重定向

  • 通过 SSH 会话使用 NET USER 命令拒绝访问

  • SSH 服务器零日漏洞利用 - 保护自己的建议

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

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