【问题标题】:/bin/sh: passwd: command not found/bin/sh: passwd: 找不到命令
【发布时间】:2020-03-28 12:11:51
【问题描述】:

我尝试执行 Docker-compose 构建但收到以下错误。

我正在使用 centos7 并且对 Linux 完全陌生。

/bin/sh: passwd: command not found.
ERROR: Service 'remote_host' failed to build: The command '/bin/sh -c useradd remote_user &&     echo "welcome1" | passwd remote_user --stdin &&     mkdir /home/remote_user/.ssh &&     chmod 700 /home/remote_user/.ssh' returned a non-zero code: 127.

DockerFile.

FROM centos: latest
RUN yum -y install OpenSSH-server

RUN useradd remote_user && \
    echo "welcome1" | passwd remote_user --stdin && \
    mkdir /home/remote_user/.ssh && \
    chmod 700 /home/remote_user/.ssh`enter code here`

COPY remote-key.pub /home/remote_user/.ssh/authorized_keys

RUN chown remote_user:remote_user -R /home/remote_user chmod 600 /home/remote_user/.ssh/authorized_keys

RUN /usr/sbin/sshd-keygen

CMD /usr/sbin/sshd -D

whoami: mosses987 $PATH:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/mosses987/.local/bin:/home/mosses987/bin

【问题讨论】:

  • 没有预装。如果您运行docker container run --rm -it centos,您可以检查/usr/bin (ls -l /usr/bin) 中的内容。
  • sh 存在于 /usr/bin [root@df322206d5a6 bin]# sh sh-4.4#
  • sh 是但 passwd 不是。你的错误是passwd: command not found
  • 它也有密码 [mosses987@localhost bin]$ find -L /bin/ -name "passwd" /bin/passwd
  • 您是在容器中搜索还是在本地机器上搜索?

标签: linux docker jenkins docker-compose


【解决方案1】:

添加这行代码:

RUN yum install -y passwd

并评论这一行:

RUN /usr/sbin/sshd-keygen

【讨论】:

    【解决方案2】:

    这应该可行,

    FROM centos
    
    RUN yum -y install openssh-server
    
    RUN yum install -y passwd
    
    RUN useradd remote_user && \
        echo "1234" | passwd remote_user --stdin && \
        mkdir /home/remote_user/.ssh && \
        chmod 700 /home/remote_user/.ssh
    
    COPY remote-key.pub /home/remote_user/.ssh/authorized_keys
    
    RUN chown remote_user:remote_user -R /home/remote_user/.ssh/ && \
        chmod 600 /home/remote_user/.ssh/authorized_keys
    
    #RUN /usr/sbin/sshd-keygen
    
    CMD /usr/sbin/sshd -D
    

    【讨论】:

      【解决方案3】:

      添加这一行

      运行 yum install -y passwd

      【讨论】:

        【解决方案4】:

        你需要安装passwd,因为远程主机没有passwd installed。在passwd 命令之前添加以下行。

        RUN yum install -y passwd 
        

        【讨论】:

          【解决方案5】:

          应该可以的

          FROM centos:7
          
          
          RUN yum update -y && \
              yum -y install openssh-server && \
              yum install -y passwd
          
          
          RUN useradd remote_user  && \
              echo "1234" | passwd remote_user --stdin && \
              mkdir /home/remote_user/.ssh && \
              chmod 700 /home/remote_user/.ssh
          
          
          COPY remote-key.pub /home/remote_user/.ssh/authorized_keys
          
          
          RUN chown -R remote_user:remote_user /home/remote_user/.ssh && \
              chmod -R 600 /home/remote_user/.ssh/authorized_keys
          
          
          RUN /usr/sbin/sshd-keygen
          
          
          CMD /usr/sbin/sshd -D
          

          【讨论】:

            猜你喜欢
            • 2021-11-13
            • 2019-04-19
            • 2013-05-16
            • 2018-08-10
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多