SSH Key to Github fails on Jenkins v2.440.3 Only

Running on a server running Red Hat Linux 9 (9.4). I am unable to use any valid SSH key to connect Jenkins to my Git repository.

The steps I took:
1.) I created the public and private key using ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

2.). I copied the public ssh key to my github account.

3.) I added github to my known hosts using ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts

4.) I started an agent.

5.) I granted permissions to Jenkins using

# Set the permissions on the .ssh directory
chmod 700 .ssh

# Set the permissions on the private key
chmod 600 .ssh/id_rsa

# Set the permissions on the public key
chmod 644 .ssh/id_rsa.pub

# Optionally, set the permissions on the known_hosts file
chmod 644 .ssh/known_hosts

6.) ssh -T git@github.ibm.com succeeds.

7.) I copied the private key to Jenkins.

Yet, for some reason, Jenkins fails to connect using the key. It says Permission denied (publickey)

If anyone. has any ideas as to why this is happening, I would be thankful to hear them. Thank you.

I don’t know if it is related to your issue but prefer ed25519 over rsa for ssh. Not all rsa keys are still compatible with GH nowadays. The ed25519 is faster and more secure.

That said, we only use https for our jenkins instances because this allows us to use API keys which have much more fine grained access control than ssh and allows us to call the GH APIs to perform things not available through the git protocol. You will have to declare the API Key as a Jenkins secret, and it will share it with the agents when they try to clone your repositories, at least if you use the Jenkins Git/GitHub plugins to perform the clones for you.

If you can, even better, create a GitHub application, this does not consume a paid user on GH and the API rate limit is 3x that of a regular user and overall even more secure than using ssh.