当ssh到容器问密码
我创build了一个docker镜像,经过testing用SSHlogin容器。 但是,当我尝试SSH容器,我被问到的根密码。 任何想法来解决它。
Dockerfile
FROM ubuntu:trusty RUN apt-get update RUN apt-get install -y openssh-server supervisor vim build-essential git RUN mkdir -p /var/run/sshd ADD supervisord/sshd.conf /etc/supervisor/conf.d/sshd.conf RUN echo 'root:root' | chpasswd EXPOSE 22 CMD ["/usr/bin/supervisord"]
supervisord / sshd.conf
[supervisord] nodaemon=true [program:sshd] command=/usr/sbin/sshd -D
您需要将公钥添加到容器root/.ssh/authorized_keys
如果sshd没有find你的公钥,它将回退到用户名/密码authentication。
一个例子是“ 在Docker镜像上设置ssh公钥 ”,但是我不喜欢它,因为它意味着容器有私钥(它不需要它)
最好是:
- 在本地生成您的公钥/私钥。
- 在您的Dockerfile中添加一个
COPY yourPublicKey /root/.ssh/authorized_keys
这会生成一个图像,其容器可以被ssh访问。
确保在你的主机上,你的$HOME/.ssh
具有私钥id_rsa
和公钥id_rsa.pub
。
这使得你的docker主机和你的docker集装箱之间的SSHauthentication,遵循以下显示的一般(即, 不是特定于docker)sshauthentication机制:
(来自SébastienSaunier的 “ GitHub公钥authentication ”,来自@ssaunier )