# SSH Key to Github fails on Jenkins v2.440.3 Only

**URL:** <https://community.jenkins.io/t/ssh-key-to-github-fails-on-jenkins-v2-440-3-only/15341>\
**Category:** Ask a question\
**Created:** [May 21, 2024, 4:03pm UTC](https://community.jenkins.io/t/ssh-key-to-github-fails-on-jenkins-v2-440-3-only/15341 "2024-05-21T16:03:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moosn](https://avatars.discourse-cdn.com/v4/letter/m/e8c25b/32.png) [@Moosn](https://community.jenkins.io/u/Moosn)\
**Post date:** [May 21, 2024, 4:03pm UTC](https://community.jenkins.io/t/ssh-key-to-github-fails-on-jenkins-v2-440-3-only/15341/1 "2024-05-21T16:03:45Z")

</div>

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

```bash
# 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.

---

<div class="post-metadata">

**Author:** ![sodul](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/sodul/32/7828_2.png) [@sodul](https://community.jenkins.io/u/sodul)\
**Post date:** [May 22, 2024, 4:19pm UTC](https://community.jenkins.io/t/ssh-key-to-github-fails-on-jenkins-v2-440-3-only/15341/2 "2024-05-22T16:19:50Z")

</div>

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.

> **[Generating a new SSH key and adding it to the ssh-agent - GitHub Docs](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#generating-a-new-ssh-key)**
>
> After you've checked for existing SSH keys, you can generate a new SSH key to use for authentication, then add it to the ssh-agent.

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.
