Home > Mobile >  Connecting to docker openssh-server with key: Permission denied (publickey,keyboard-interactive)
Connecting to docker openssh-server with key: Permission denied (publickey,keyboard-interactive)

Time:03-28

I am trying to connect to openssh-server in docker container using ssh:

$ docker run -d \
  --name=openssh-server \
  --hostname=openssh-server \
  -e PUID=1000 \
  -e PGID=1000 \
  -e PUBLIC_KEY_FILE=/home/hakon/.ssh/id_rsa.pub \
  -e SUDO_ACCESS=false \
  -e PASSWORD_ACCESS=false \
  -e USER_NAME=hakonh \
  -p 2222:2222 \
  --restart unless-stopped \
  lscr.io/linuxserver/openssh-server

$ docker inspect -f "{{ .NetworkSettings.IPAddress }}" openssh-server
172.17.0.2

$ ping -c 3  172.17.0.2
PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.071 ms
64 bytes from 172.17.0.2: icmp_seq=2 ttl=64 time=0.039 ms
64 bytes from 172.17.0.2: icmp_seq=3 ttl=64 time=0.059 ms    
--- 172.17.0.2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2028ms
rtt min/avg/max/mdev = 0.039/0.056/0.071/0.013 ms

$ ssh -i /home/hakon/.ssh/id_rsa -p 2222 [email protected]
The authenticity of host '[172.17.0.2]:2222 ([172.17.0.2]:2222)' can't be established.
ECDSA key fingerprint is SHA256:6xSuNXvqvL1XM7d8//s1TN OWb6GLdstA PUpFlqP8M.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[172.17.0.2]:2222' (ECDSA) to the list of known hosts.
[email protected]: Permission denied (publickey,keyboard-interactive).

What am I missing here? Why am I not allowed to connect to the server with private key?

CodePudding user response:

You're using the environnement variable PUBLIC_KEY_FILE with the value /home/hakon/.ssh/id_rsa.pub which indicate to your ssh server to use this file as your authorized key, however from what I can see your docker doesn't have acces to this file as I suppose it is the path of the file inside your system not inside your docker. I suggest that you share this file with your docker using a volume or copy it in an image built from lscr.io/linuxserver/openssh-server.

  • Related