2016-07-27 66 views
1

我有一个CentOS 6.4实例。如何从centos 6.4 ssh到没有密码的码头容器?

在此实例中,我无法将RSA密钥ssh ssh转换为基于CentOS 6.7的Docker容器。

在Ubuntu(Trusty)和Amazon Linux实例上,我可以SSH入Docker容器。

我需要使用ssh命令(真正可行)而不是docker exec

我正在运行的命令是ssh -i id_rsa -p 2200 [email protected]

我Dockerfile看起来像这样:

From centos:6.7 

#update yum repository and install openssh server 
RUN yum update -y 
RUN yum install -y openssh-server 
RUN yum install -y sudo 

RUN useradd user 

RUN echo "user ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers 

RUN mkdir -p /home/user/.ssh 
ADD id_rsa.pub /home/user/.ssh/authorized_keys 

RUN chown user /home/user/.ssh -R 
RUN chmod 600 /home/user/.ssh/authorized_keys 

#generate ssh key 
RUN ssh-keygen -q -N "" -t rsa -f /etc/ssh/ssh_host_rsa_key 

EXPOSE 22 
CMD ["sh","-c","/usr/sbin/sshd -D;sleep 1"] 

我已经检查的权限上的所有文件(私钥和公钥,authorized_keys文件)和目录(/.ssh)。

事实上,我可以ssh亚马逊Linux到这个容器让我相信这个问题不是来自我的码头容器,也没有文件和文件夹的权限。

我已经更改了Docker容器和本地CentOS上的PAM。

我已经更新了Python到2.7.12(因为这真的是为了......不管)。

容器正在运行。

我已经删除了known_hosts。

使用ssh配置。

当添加-vvvvvssh命令我得到这个问题:

debug3: Not a RSA1 key file /path/to/project/dir/id_rsa. 
debug2: key_type_from_name: unknown key type '-----BEGIN' 
debug3: key_read: missing keytype 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug3: key_read: missing whitespace 
debug2: key_type_from_name: unknown key type '-----END' 
debug3: key_read: missing keytype 

回答

1

在服务器端的常见问题有:

    对〜/ .ssh/authorized_keys的
  1. 权限应该是400/600(仅限拥有者的权限)。
  2. PAM安全性可能是一个问题,您应该禁用PAM sshd_config。
  3. 必须启用(出现在/ etc/shadow上)将会“进入”服务器(例如centos)的用户。
  4. 应在sshd_config上启用RSA。

解决方案:

  1. 作为用户ssh方式连接到(例如的centos @server):

    chmod 600 ~/.ssh/authorized_keys

  2. 作为根:如果需要的话

    sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config service sshd reload

  3. 用户 “的centos”(变化):

    passwd -u -f centos

  4. 作为根:

    sed -i 's/RSAAuthentication no/RSAAuthentication yes/g service sshd reload


在客户端,只记得交出了钥匙和钥匙应该有600权限了。例如: ssh -i myrsa.key [email protected]

+0

我将此添加到我的Dockerfile:'RUN SED -i 'S/UsePAM是/ UsePAM没有/ G' 的/ etc/SSH/sshd_config中 运行yum安装的passwd -y 通过运行passwd -f -u centos' –

0

在您的主机试试这个:

chmod 700 ~/.ssh 

chmod 600 ~/.ssh/authorized_keys 

sed -i 's|#AuthorizedKeysFile|AuthorizedKeysFile|g' /etc/ssh/sshd_config 
sed -i 's|.ssh/authorized_keys|%h/.ssh/authorized_keys|g' /etc/ssh/sshd_config