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 / 问题 / 407497
Accepted
andrew
andrew
Asked: 2012-07-14 04:53:49 +0800 CST2012-07-14 04:53:49 +0800 CST 2012-07-14 04:53:49 +0800 CST

如何配置 SSHd 以允许单个命令,而不向用户提供完全登录访问权限?

  • 772

我正在寻找通过 SSH 调用远程命令的最佳方式。我创建用户“rpcall”,生成新证书并填写 authorized_keys。用更多的方式保护它

from="ip",no-agent-forwarding,no-X11-forwarding,no-port-forwarding,no-pty ssh-rsa ......

现在用户 rpcall 无法登录到终端

ssh -l rpc 192.168.12.1
PTY allocation request failed on channel 0

但是可以运行任何命令

ssh -l rpc 192.168.12.1 cat /etc/passwd

有什么解决方案可以将命令执行限制在一个处理脚本中吗?例如/home/rpcall/bin/command.sh

我为此用户设置了 bash shell 并使用 .bashrc 强制运行处理脚本,但我不知道如何从 ssh 调用传递参数。

.bashrc 用户 rpcall

/home/rpcall/bin/command.sh $params1 $params2
exit

从其他机器ssh调用

ssh -l rpcall 192.168.12.1 "param1" "param2"
ssh remote exec
  • 1 1 个回答
  • 10432 Views

1 个回答

  • Voted
  1. Best Answer
    EightBitTony
    2012-07-14T05:23:29+08:002012-07-14T05:23:29+08:00

    您可以使用 authorized_keys 文件限制命令。放在command="/home/rpcall/bin/command.sh"密钥之前,在 authorized_keys 文件中,用户只会在连接时运行该命令。

    检查 authorized_keys 的手册页,这是来自该手册页,

     command="command"
             Specifies that the command is executed whenever this key is used
             for authentication.  The command supplied by the user (if any) is
             ignored.  The command is run on a pty if the client requests a
             pty; otherwise it is run without a tty.  If an 8-bit clean chan-
             nel is required, one must not request a pty or should specify
             no-pty.  A quote may be included in the command by quoting it
             with a backslash.  This option might be useful to restrict cer-
             tain public keys to perform just a specific operation.  An exam-
             ple might be a key that permits remote backups but nothing else.
             Note that the client may specify TCP and/or X11 forwarding unless
             they are explicitly prohibited.  The command originally supplied
             by the client is available in the SSH_ORIGINAL_COMMAND environ-
             ment variable.  Note that this option applies to shell, command
             or subsystem execution.
    

    如果你需要一个以上的命令,你基本上需要设置几组按键,使用不同的按键给你不同的命令。

    编辑:我刚刚注意到,原始命令在SSH_ORIGINAL_COMMAND环境变量中可用,因此您确实可以使用自己的脚本处理该输入,做一些聪明的事情。

    • 19

相关问题

  • 如何最好地设置 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