2016-07-27 62 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