1

on my host server I have my user with generated private and public keys. I have copied public key value to my remote server authorized_keys file. I have mapped new docker container instance to use the .ssh folder as a volume and set network to the host's network.

-v /home/jenkins/.ssh:/home/jenkins/.ssh --network host'

Now I try to SSH authenticate myself inside the container towards the remote computer.

ssh -vvv -o StrictHostKeyChecking=no [email protected]

My user does not have SSH pass phrase. Output on the SSH server side:

sshd: Failed none for jenkins from 10.7.148.219 port 42058 ssh2
sshd: Failed password for jenkins from 10.7.148.219 port 42058 ssh2

Output on the client side:

+ ssh -vvv -o 'StrictHostKeyChecking=no' [email protected]
OpenSSH_8.6p1, OpenSSL 1.1.1l  24 Aug 2021
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolve_canonicalize: hostname 10.7.175.143 is address
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/root/.ssh/known_hosts'
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts2' -> '/root/.ssh/known_hosts2'
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug3: ssh_connect_direct: entering
debug1: Connecting to 10.7.175.143 [10.7.175.143] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x48
debug1: Connection established.
.................................

debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug3: start over, passed a different list publickey,password,keyboard-interactive
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug3: no such identity: /root/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_dsa
debug3: no such identity: /root/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ecdsa
debug3: no such identity: /root/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /root/.ssh/id_ecdsa_sk
debug3: no such identity: /root/.ssh/id_ecdsa_sk: No such file or directory
debug1: Trying private key: /root/.ssh/id_ed25519
debug3: no such identity: /root/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /root/.ssh/id_ed25519_sk
debug3: no such identity: /root/.ssh/id_ed25519_sk: No such file or directory
debug1: Trying private key: /root/.ssh/id_xmss
debug3: no such identity: /root/.ssh/id_xmss: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup keyboard-interactive
debug3: remaining preferred: password
debug3: authmethod_is_enabled keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug3: send packet: type 50
debug2: we sent a keyboard-interactive packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug3: userauth_kbdint: disable: no info_req_seen
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: 
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
debug1: read_passphrase: can't open /dev/tty: No such device or address
debug3: send packet: type 50
debug2: we sent a password packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey,password,keyboard-interactive).

Can I somehow authenticate my self from the docker container?

5
  • If it works from a bare-metal host (not from a container), you should run the same ssh command from there (assuming it succeeds) and compare the verbose output between the successful and failed ssh runs, look for differences that might give you some hint. You should also compare /etc/ssh/ssh_config you have in the docker and the one you have on your host, maybe there are some differences that cause the failure and you you will need to copy it to the docker image.
    – aviro
    Nov 30, 2021 at 14:49
  • 2
    Actually, I see now in your outptut that it searches for the ssh keys in /root instead of jenkins home folder. You should tell ssh where it should look for the keys.
    – aviro
    Nov 30, 2021 at 14:50
  • @aviro that's it! You resolved it!!! I assumed that it targets /home/jenkins/.ssh by default - I am surprised that it uses /root by default. I referenced with -i and now it works! Can you please tell me for the "scp" how I can reference the private key as well? Because I need to use scp command after the ssh command. If it targets by default /home/jenkins/.ssh I wouldn't have issue but now I don't know how to reference in SCP? Thanks
    – AndreyS
    Nov 30, 2021 at 15:02
  • scp should also have the same -i flag, just like ssh.
    – aviro
    Nov 30, 2021 at 15:05
  • Thanks! You can put an answer so I could accept it
    – AndreyS
    Nov 30, 2021 at 15:08

1 Answer 1

4

From your debug output, you could see that since you're running the ssh command as root, it searches for the ssh keys in root's home folder instead of jenkins home folder.

debug1: Trying private key: /root/.ssh/id_rsa
debug3: no such identity: /root/.ssh/id_rsa: No such file or directory

You should provide the location of your private key by adding the -i <identity_file> flag to your ssh command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .