0

I have installed Jenkins and when I go for

git push
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I added SSH key enter image description here

I checked form my repo

git config --list
user.email=my.name@gmail.com
user.name=My Name
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:myname/jenkinskode.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.main.remote=origin
branch.main.merge=refs/heads/main

My .ssh on VM

-rw------- 1 miki miki  599 Sep 20 10:34 authorized_keys
-rw------- 1 miki miki 3243 Sep 22 09:16 id_github
-rw-r--r-- 1 miki miki  752 Sep 22 09:16 id_github.pub
-rw-r--r-- 1 miki miki  888 Sep 22 09:11 known_hosts

I double checked everything. Output ssh-Tv

ssh -Tv git@github.com
OpenSSH_7.6p1 Ubuntu-4ubuntu0.7, OpenSSL 1.0.2n  7 Dec 2017
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [140.82.113.4] port 22.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /home/miki/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miki/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miki/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miki/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miki/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miki/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miki/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/miki/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.7
debug1: Remote protocol version 2.0, remote software version babeld-24a5c4c2
debug1: no match: babeld-24a5c4c2
debug1: Authenticating to github.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:*****************************
debug1: Host 'github.com' is known and matches the ECDSA host key.
debug1: Found key in /home/miki/.ssh/known_hosts:1
Warning: Permanently added the ECDSA host key for IP address '140.82.113.4' to the list of known hosts.
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/miki/.ssh/id_rsa
debug1: Trying private key: /home/miki/.ssh/id_dsa
debug1: Trying private key: /home/miki/.ssh/id_ecdsa
debug1: Trying private key: /home/miki/.ssh/id_ed25519
debug1: No more authentication methods to try.
git@github.com: Permission denied (publickey).

And ssh-agent

ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-FhrOT4qqIvV7/agent.17863; export SSH_AUTH_SOCK;
SSH_AGENT_PID=17864; export SSH_AGENT_PID;
echo Agent pid 17864;

How to solve this problem?

phd
  • 82,685
  • 13
  • 120
  • 165
Richard Rublev
  • 7,718
  • 16
  • 77
  • 121
  • 1
    "*I added SSH key…*" `ssh-agent`? `ssh -Tv git@github.com` ? – phd Sep 22 '22 at 10:21
  • @phd take a look,should I create id_rsa? – Richard Rublev Sep 22 '22 at 10:31
  • 1
    Not create but rename existing: `id_github` -> `id_rsa`, `id_github.pub` -> `id_rsa.pub`. Or add the key to agent: `ssh-add ~/.ssh/id_github`. Or make (in `~/.ssh/config`) SSH use the key when connecting to github.com. See the answers at https://stackoverflow.com/q/21095054/7976758 Found in https://stackoverflow.com/search?q=%5Bgit%5D+ssh+github.com – phd Sep 22 '22 at 11:20

0 Answers0