0

I have tried these steps a number of time but failing. Did lot of RnD but could not fix the issue.

I am using CentOS running on Oracle VM.

I am trying to connect from CentOS host -> Jenkins -> Remote Host using SSH

My present working directory is : /root/connect2nareshc/jenkins_0_to_hero/jenkins_image I did ssh-keygen -f remote-key to generate public and private keys.

In the directory /root/connect2nareshc/jenkins_0_to_hero/jenkins_image I have Dockerfile as follows:

FROM centos:7

RUN yum -y install openssh-server

RUN useradd remote_user  && \
    echo "1234" | passwd remote_user --stdin && \
    mkdir /home/remote_user/.ssh && \
    chmod 700 /home/remote_user/.ssh

COPY remote-key.pub /home/remote_user/.ssh/authorized_keys

RUN chown remote_user:remote_user -R /home/remote_user/.ssh && \
    chown 600 /home/remote_user/.ssh/authorized_keys

RUN ssh-keygen -A

CMD /usr/sbin/sshd -D

In one directory above in /root/connect2nareshc/jenkins_0_to_hero, I have docker-compose.yml as follows:

version: '3'
services:
  jenkins:
    container_name: jenkins_yml
    image: "jenkins/jenkins:lts"
    ports:
      - 8080:8080
    networks:
      - net
  remote_host:
    container_name: remote-host
    image: remote_host
    build:
      context: /root/connect2nareshc/jenkins_0_to_hero/jenkins_image
    networks:
      - net
networks:
  net:

I execute the following command and it works fine. I.e. From host I connect to Jenkins and from Jenkins I connect to remote_host using password.

docker-compose build
docker-compose up -d
docker exec -it jenkins_yml bash
ssh remote_user@remote_host
#Enter password 1234 when prompted.

When I try to connect using keys, I am not able to:

docker cp remote-key jenkins_yml:/tmp/remote-key
docker exec -it jenkins_yml bash
cd /tmp
ssh -i remote-key remote_user@remote_host

Instead it prompts me to connect with password.

While on remote_host I did ls -altr on /var/log and got following output. I cannot find auth.log

drwxr-xr-x. 1 root root   4096 May  4 15:36 ..
-rw-r--r--. 1 root root    193 May  4 15:36 grubby_prune_debug
-rw-------. 1 root utmp      0 May  4 15:36 btmp
drwxr-xr-x. 1 root root   4096 May  4 15:37 .
-rw-------. 1 root root   1751 Jul 28 16:35 yum.log
-rw-------. 1 root root  64064 Jul 28 16:36 tallylog
-rw-rw-r--. 1 root utmp   1152 Jul 29 03:17 wtmp
-rw-r--r--. 1 root root 292292 Jul 29 03:17 lastlog
Naresh Chaurasia
  • 419
  • 5
  • 21
  • When none of this worked I also did use `ssh-keygen -t rsa -b 4096 -m PEM -f remote-key` and `chmod 777 remote-key` in the beginning. – Naresh Chaurasia Jul 29 '20 at 03:38
  • try `chmod 400 remote-key` – WSMathias9 Jul 29 '20 at 05:27
  • I get following error: `Load key "remote-key": Permission denied` – Naresh Chaurasia Jul 29 '20 at 06:38
  • I connected to remote_host as root using following command docker exec -u 0 -it ede885f1c422 bash When I run the following command cat /etc/ssh/sshd_config | more | grep "Auth" , I find the following entry #PubkeyAuthentication yes. How can i remove this comment '#PubkeyAuthentication yes', while creating the image. I think that because this line is commented, I am not able to do ssh. – Naresh Chaurasia Jul 29 '20 at 07:22
  • no need to change that defaut is yes only – WSMathias9 Jul 30 '20 at 05:04

0 Answers0