首页 > 解决方案 > 无法启动 shell: 无法启动 pty: fork/exec /usr/bin/sh: operation not allowed

问题描述

我正在尝试在本地环境的非 root 用户下安装和运行 AWS SSM 代理。例如,我将 amazon-ssm-agent 进程作为操作系统上的 ec2-user 启动。注册没有问题,我可以在 AWS SSM 控制台中看到 Ping 状态为“在线”。但是,当我尝试通过会话管理器对实例启动会话时,它总是失败并提示如下错误:

"Output": "\n----------ERROR-------\nUnable to start shell: Failed to start pty: fork/exec /usr/bin/sh: operation not permitted

相关的源代码片段是这样的:

func StartPty(
    log log.T,
    shellProps mgsContracts.ShellProperties,
    isSessionLogger bool,
    config agentContracts.Configuration,
    plugin *ShellPlugin) (err error) {

    log.Info("Starting pty")
    //Start the command with a pty
    var cmd *exec.Cmd
    if strings.TrimSpace(shellProps.Linux.Commands) == "" || isSessionLogger {
        cmd = exec.Command("sh")
    } else {
        commandArgs := append(utility.ShellPluginCommandArgs, shellProps.Linux.Commands)
        cmd = exec.Command("date", commandArgs...)
    }

....

    ptyFile, err = pty.Start(cmd)
    if err != nil {
        log.Errorf("Failed to start pty: %s\n", err)
        return fmt.Errorf("Failed to start pty: %s\n", err)
    }

最初我虽然可能是该 shell 二进制文件的权限问题。但这并没有什么问题,每个人都可以运行 shell 命令。

有人知道这里发生了什么并对如何解决有任何建议吗?谢谢

顺便说一句,AWS SSM 代理源代码基于 Go 编程语言。

标签: goaws-ssm

解决方案


推荐阅读