2

So I am trying to set up a ssh key for Jenkins. For some reason I am getting:

Permission denied (publickey). 

The full stack trace is:

[jenkins@ip-xx-xx-xx-xxx .ssh]$ ls
authorized_keys  id_rsa  id_rsa.pub  known_hosts
[jenkins@ip-xx-xx-x-xxx .ssh]$ ssh -vT ddennis@git.xxxxxx.com
OpenSSH_6.6.1, OpenSSL 1.0.1k-fips 8 Jan 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to git.viasat.com [xx.xx.xxx.xx] port 22.
debug1: Connection established.
debug1: identity file /home/jenkins/.ssh/id_rsa type 1
debug1: identity file /home/jenkins/.ssh/id_rsa-cert type -1
debug1: identity file /home/jenkins/.ssh/id_dsa type -1
debug1: identity file /home/jenkins/.ssh/id_dsa-cert type -1
debug1: identity file /home/jenkins/.ssh/id_ecdsa type -1
debug1: identity file /home/jenkins/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/jenkins/.ssh/id_ed25519 type -1
debug1: identity file /home/jenkins/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1
debug1: Remote protocol version 2.0, remote software version libssh-0.7.0
debug1: no match: libssh-0.7.0
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: kex: ecdh-sha2-nistp256 need=20 dh_need=20
debug1: kex: ecdh-sha2-nistp256 need=20 dh_need=20
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA aa:f3:39:39:58:2b:61:ad:e8:d3:7a:f2:d2:e9:dd:7a
debug1: Host 'git.xxxxxx.com' is known and matches the ECDSA host key.
debug1: Found key in /home/jenkins/.ssh/known_hosts:3
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/jenkins/.ssh/id_rsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/jenkins/.ssh/id_dsa
debug1: Trying private key: /home/jenkins/.ssh/id_ecdsa
debug1: Trying private key: /home/jenkins/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

I have the ssh key set up as my user in git as well.
I ran:

[jenkins@ip-xx-xx-xx-xxx .ssh]$ ssh-add -l
4096 9e:93:0c:12:4c:74:a6:e4:f0:eb:a1:28:d4:44:46:71 /home/jenkins/.ssh/id_rsa (RSA)

on my slave node and it matched the one that was loaded into git.
I also did a copy of that key into my authorized key file.
Been playing around with this for a while any advice is helpful.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
David Dennis
  • 702
  • 2
  • 9
  • 26

1 Answers1

2

First try to generate an ssh key without passphrase: that way you don't have to worry with ssh-add.

ssh-keygen -t rsa -C "key for xxx access" -q -P ""

(no need for putty as seen in "AWS Troubleshooting Instances Connecting")
(no need for the console, which creates ppk/pem ssh keys)

Make sure the permissions are correct, both on the client and server side, regarding ssh.

Make sure you have correctly copied the public key in the server:

~/ddennis/.ssh/authorized_keys 

(as one continuous line)


After that, if ssh -Tv does work, but Jenkins itself does not work, it generally is because Jenkins is not running with the same account, and does not look for the same set of ssh keys.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • So this seemed to fix it. I must have been a permission thing. But for some reason on Jenkins i'm still getting returned status code 128: stdout: stderr: Permission denied (publickey). fatal: Could not read from remote repository. But it's pulling the code and building successfully. If you have any insight to that. Seems very weird for me. – David Dennis Jun 19 '17 at 19:38
  • @DavidDennis if ssh -Tv does work, but Jenkins itself does not work, it generally is because Jenkins is not running with the same account, and does not look for the same set of ssh keys. – VonC Jun 19 '17 at 19:40
  • that's that answer I was looking for. Thank you. – David Dennis Jun 19 '17 at 19:44
  • @DavidDennis Great! I have included the comment in the answer for more visibility. – VonC Jun 19 '17 at 19:45