1

I am experiencing publickey permission issues when trying to pull a private repo from GitHub to a remote Linux server.

Update

Ran ssh -v -o IdentitiesOnly=yes -i ~/.ssh/id_rsa [email protected] command on local Terminal

OpenSSH_9.0p1, LibreSSL 3.3.6
debug1: Reading configuration data /Users/username/.ssh/config
debug1: /Users/username/.ssh/config line 88: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to github.com port 22.
debug1: Connection established.
debug1: identity file /Users/username/.ssh/id_rsa type 0
debug1: identity file /Users/username/.ssh/id_rsa-cert type -1
debug1: identity file /Users/username/.ssh/id_rsa type 0
debug1: identity file /Users/username/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_9.0
debug1: Remote protocol version 2.0, remote software version babeld-dd067d10
debug1: compat_banner: no match: babeld-dd067d10
debug1: Authenticating to github.com:22 as 'git'
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'github.com' is known and matches the ED25519 host key.
debug1: Found key in /Users/username/.ssh/known_hosts:92
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: get_agent_identities: bound agent to hostkey
debug1: get_agent_identities: agent returned 1 keys
debug1: Will attempt key: /Users/username/.ssh/id_rsa RSA SHA256:ByqPOdPMwOMKXVfMItyopkVjqG/iZHpOjMgPPwrE7J0 explicit agent
debug1: Will attempt key: /Users/username/.ssh/id_rsa RSA SHA256:ByqPOdPMwOMKXVfMItyopkVjqG/iZHpOjMgPPwrE7J0 explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],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: Offering public key: /Users/username/.ssh/id_rsa RSA SHA256:ByqPOdPMwOMKXVfMItyopkVjqG/iZHpOjMgPPwrE7J0 explicit agent
debug1: Server accepts key: /Users/username/.ssh/id_rsa RSA SHA256:ByqPOdPMwOMKXVfMItyopkVjqG/iZHpOjMgPPwrE7J0 explicit agent
Authenticated to github.com ([140.82.113.3]:22) using "publickey".
debug1: channel 0: new [client-session]
debug1: Entering interactive session.
debug1: pledge: filesystem
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: client_input_hostkeys: searching /Users/username/.ssh/known_hosts for github.com / (none)
debug1: client_input_hostkeys: searching /Users/username/.ssh/known_hosts2 for github.com / (none)
debug1: client_input_hostkeys: no new or deprecated keys from server
debug1: Sending environment.
debug1: channel 0: setting env LANG = "en_CA.UTF-8"
PTY allocation request failed on channel 0
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
debug1: channel 0: free: client-session, nchannels 1
Connection to github.com closed.
Transferred: sent 3368, received 2956 bytes, in 0.1 seconds
Bytes per second: sent 22573.3, received 19811.9
debug1: Exit status 1

username replaces the actual username on the server.

I have created an empty directory on the server and initialized Git using git init. The permissions and ownership are set to drwxr-xr-x 3 username username 4.0K Oct 18 14:19 testing.

The GitHub repo was added using git remote add origin [email protected]:<username>/<repo_name>.git.

The command git remote -v returns:

origin  [email protected]:<username>/<repo_name>.git (fetch)
origin  [email protected]:<username>/<repo_name>.git (push)

When I run git pull origin main, the following is returned in the Terminal

[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

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

The publickey on my GitHub account is seemingly correct as I have cloned and pulled various repos from there to my local computer using the SSH keys.

To check for potential corruption issues, I deleted all of my keys on the GitHub account and added the id_rsa.pub key again. I use this key on all of my remote Linux servers and I have no connection or permission issues with them.

I have run ssh -vT [email protected] from one of the affected servers and have included the output below.

OpenSSH_8.9p1 Ubuntu-3ubuntu0.4, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to github.com [140.82.113.3] port 22.
debug1: Connection established.
debug1: identity file /home/username/.ssh/id_rsa type -1
debug1: identity file /home/username/.ssh/id_rsa-cert type -1
debug1: identity file /home/username/.ssh/id_ecdsa type -1
debug1: identity file /home/username/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/username/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/username/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/username/.ssh/id_ed25519 type -1
debug1: identity file /home/username/.ssh/id_ed25519-cert type -1
debug1: identity file /home/username/.ssh/id_ed25519_sk type -1
debug1: identity file /home/username/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/username/.ssh/id_xmss type -1
debug1: identity file /home/username/.ssh/id_xmss-cert type -1
debug1: identity file /home/username/.ssh/id_dsa type -1
debug1: identity file /home/username/.ssh/id_dsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.4
debug1: Remote protocol version 2.0, remote software version babeld-dc5ec9be
debug1: compat_banner: no match: babeld-dc5ec9be
debug1: Authenticating to github.com:22 as 'git'
debug1: load_hostkeys: fopen /home/username/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU
debug1: load_hostkeys: fopen /home/username/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory
debug1: Host 'github.com' is known and matches the ED25519 host key.
debug1: Found key in /home/username/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/username/.ssh/id_rsa 
debug1: Will attempt key: /home/username/.ssh/id_ecdsa 
debug1: Will attempt key: /home/username/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /home/username/.ssh/id_ed25519 
debug1: Will attempt key: /home/username/.ssh/id_ed25519_sk 
debug1: Will attempt key: /home/username/.ssh/id_xmss 
debug1: Will attempt key: /home/username/.ssh/id_dsa 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],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/username/.ssh/id_rsa
debug1: Trying private key: /home/username/.ssh/id_ecdsa
debug1: Trying private key: /home/username/.ssh/id_ecdsa_sk
debug1: Trying private key: /home/username/.ssh/id_ed25519
debug1: Trying private key: /home/username/.ssh/id_ed25519_sk
debug1: Trying private key: /home/username/.ssh/id_xmss
debug1: Trying private key: /home/username/.ssh/id_dsa
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).

The permissions and ownership for the user's ~/.ssh directories and files are:

drwx------ 2 username username 4.0K Oct 18 15:26 .ssh
-rw------- 1 username username 595 Oct 18 15:04 authorized_keys
-rw------- 1 username username 142 Oct 18 14:03 known_hosts

The publickey has been copied using pbcopy < ~/.ssh/id_rsa.pub and manually from my computer for testing purposes.

The permission issues apply to repos under the main account user and the organization I have attached to the account.

I interact with the server using sudo, though all git commands do not use it.

I have tried creating a new SSH key pair and have added them to a server and GitHub, but the same issues occur. I used GitHub generating a new SSH key and adding it to the ssh-agent as reference.

On my MacBook, I have run the following SSH-related commands as suggested by GitHub support.

eval "$(ssh-agent -s)" returns Agent pid 28566

ssh-add -l -E sha256 returns The agent has no identities.

ssh-add --apple-use-keychain ~/.ssh/id_rsa returns Identity added: /Users/username/.ssh/id_rsa ([email protected])

After running the above command, the following is returned: 3072 SHA256:ByqPOdPMwOMKXVfMItyopkVjqG/iZHpOjMgPPwrE7J0 [email protected] (RSA)

The following is in the ~/.ssh/config file:

Host github.com
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa  

I have reviewed various help articles, but have been unable to resolved this issue. Hopefully someone here can provide some assistance.

Thanks!

2
  • You might be suffering from the ssh limit on the max number of keys (attempts) that the server accepts. Can you try ssh -v -o IdentitiesOnly=yes -i ~/.ssh/id_rsa [email protected] ? Oct 19, 2023 at 6:44
  • @JurajMartinka I ran the command in the local Terminal and have posted the output in my original question Oct 19, 2023 at 15:09

1 Answer 1

0

It looks like it's working with the updated ssh command:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

I suggest you remove the other ssh keys from the .ssh folder if they aren't necessary. Or you may configure git to use a custom SSH command: https://stackoverflow.com/questions/4565700/how-to-specify-the-private-ssh-key-to-use-when-executing-shell-command-on-git

1
  • I removed the unused key pairs and performed some further testing. Nothing came of it until I realized I was using a combination of git and sudo git for the commands. Switching exclusively to git seems have resolved the issues. Thanks for your assistance! Oct 22, 2023 at 19:43

You must log in to answer this question.

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