【问题标题】:Docker Bad owner or permissions on /root/.ssh/configDocker 错误的所有者或 /root/.ssh/config 上的权限
【发布时间】:2019-01-15 13:30:12
【问题描述】:

所以,我在Ubuntu 16.04.5 LTS 上设置了docker 17.03。问题是,应用程序需要ssh 到外部服务器。由于docker 绑定当前用户ssh 文件,它应该允许我从容器ssh 进入服务器。但是它给了我Bad owner or permissions on /root/.ssh/config 错误。

据我所知,docker 以我的 ubuntu 用户 1001 身份运行,并试图访问 root 帐户 ssh 文件(我可能是错的),这就是它给我这个错误的原因。

另外,当我从容器中运行echo $USER 时,它不会返回任何用户,而只是一个空行。

问题是,以前有没有人遇到过这个问题,如果有,有没有人解决过?

【问题讨论】:

  • 嗨,Vilius 你找到解决方案了吗?我遇到了完全相同的问题,不知道如何解决。
  • @PaulZakharov,不,不幸的是我没有。但是我确实知道一个狡猾的解决方法。您可以将 root 用户 ssh 密钥添加到外部服务器授权密钥,这将允许您连接到服务器

标签: docker ubuntu ssh permissions


【解决方案1】:

这些命令应该可以解决权限问题:

设置文件所有者:

chown $USER ~/.ssh/config

在配置上为用户设置 rw 权限:

chmod 600 ~/.ssh/config

如果chmod 600 ~/.ssh/config 不起作用,请尝试:

chmod 400 ~/.ssh/config

【讨论】:

  • 是在docker容器还是我的主机里面?第一个命令失败,因为 $USER 返回 NULL。后两个返回chmod: changing permissions of '/root/.ssh/config': Read-only file system。也就是说,如果我在 dcoker 容器中运行命令
  • 在主机上设置它
  • 还是一样的信息 :-(
【解决方案2】:

在 Linux 上, 将所有权更改为 root 为我解决了这个问题。 我还将我的用户组添加为组,因此配置也可以在 docker 之外工作。

chown root:$USER ~/.ssh/config
chmod 644 ~/.ssh/config

【讨论】:

    【解决方案3】:

    以下解决方案对我有用:https://github.com/welaika/docker-wordmove/pull/17

    这使用入口点脚本将挂载的 .ssh 目录的内容复制到 /root/.ssh 并调整所有权和权限。我稍微修改了票证的脚本以跳过 *.pub 文件,这些文件在缺席时会导致问题。

    mount-ssh.sh:

    #!/usr/bin/env bash
    set -e
    
    # Using `-v $HOME/.ssh:/root/.ssh:ro` produce permissions error while in the container
    # when working from Linux and maybe from Windows.
    # To prevent that we offer the strategy to mount the `.ssh` folder with
    # `-v $HOME/.ssh:/.ssh:ro` thus this entrypoint will automatically handle problem.
    
    if [[ -d /.ssh ]]; then
    
      cp -R /.ssh /root/.ssh
      chmod 700 /root/.ssh
      chmod 600 /root/.ssh/*
      if compgen -G "/.ssh/*.pub" > /dev/null; then
        chmod 644 /root/.ssh/*.pub
      fi
      chmod 644 /root/.ssh/known_hosts
    
    fi
    
    exec "$@"
    

    在 Dockerfile 中:

    [..]
    COPY mount-ssh.sh /bin/mount-ssh.sh
    [..]
    RUN chmod +x /bin/mount-ssh.sh
    [..]
    ENTRYPOINT ["/bin/mount-ssh.sh"]
    

    【讨论】:

      猜你喜欢
      • 2018-09-30
      • 1970-01-01
      • 2018-05-20
      • 1970-01-01
      • 2019-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-22
      相关资源
      最近更新 更多