我创建了两个Docker容器。一个Jenkins和一个运行Ubuntu Base的OpenSSH服务器的容器。我配置了Jenkins容器,购买了Jenkins镜像,并使用Dockerfile为openssh服务器创建了镜像。我生成了密钥文件并将公钥复制到openssh服务器的authorized_keys中。然后,当我尝试通过Jenkins容器使用ssh -i remote-key remote_user@remote-host登录openssh服务器时,它提示我给予密码。
下面是我的DockerFile和docker-compose DockerFile:
From ubuntu
Run apt-get update
Run apt-get install -y openssh-server
Run useradd -m -d /home/remote_user remote_user && \
echo "remote_user:1234" |chpasswd && \
mkdir -p /home/remote_user/.ssh && \
chmod 700 /home/remote_user/.ssh
Copy remote-key.pub /home/remote_user/.ssh/authorised_keys
Run chown remote_user:remote_user -R /home/remote_user/.ssh && \
chmod 600 /home/remote_user/.ssh/authorised_keys
RUN service ssh start
EXPOSE 22
CMD ["/usr/sbin/sshd","-D"]`
docker-compose
version: '3'
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
ports:
- "8080:8080"
volumes:
- "/home/sarthak/jenkins/jenkins1/jenkins1_home:/var/jenkins_home"
networks:
- net
remote_host:
container_name: remote-host
image: remote-host
build:
context: /home/sarthak/jenkins/jenkins1/
networks:
- net
networks:
net:
通过密码登录是成功的,但我需要一个密码少登录。请帮帮忙
1条答案
按热度按时间w8biq8rn1#
在创建
Dockerfile
时,您应该将authorised_keys
更改为authorized_keys
,两行有相同的问题:和/或