Error permission denied github

A "Permission denied" error means that the server rejected your connection. There could be several reasons why, and the most common examples are explained below.

Should the sudo command or elevated privileges be used with Git?

You should not be using the sudo command or elevated privileges, such as administrator permissions, with Git. If you have a very good reason you must use sudo, then ensure you are using it with every command (it’s probably just better to use su to get a shell as root at that point). If you generate SSH keys without sudo and then try to use a command like sudo git push, you won’t be using the same keys that you generated.

Check that you are connecting to the correct server

Typing is hard, we all know it. Pay attention to what you type; you won’t be able to connect to «githib.com» or «guthub.com». In some cases, a corporate network may cause issues resolving the DNS record as well.

To make sure you are connecting to the right domain, you can enter the following command:

$ ssh -vT git@github.com
> OpenSSH_8.1p1, LibreSSL 2.7.3
> debug1: Reading configuration data /Users/YOU/.ssh/config
> debug1: Reading configuration data /etc/ssh/ssh_config
> debug1: /etc/ssh/ssh_config line 47: Applying options for *
> debug1: Connecting to github.com port 22.

The connection should be made on port 22, unless you’re overriding settings to use SSH over HTTPS.

Always use the «git» user

All connections, including those for remote URLs, must be made as the «git» user. If you try to connect with your GitHub username, it will fail:

$ ssh -T GITHUB-USERNAME@github.com
> Permission denied (publickey).

If your connection failed and you’re using a remote URL with your GitHub username, you can change the remote URL to use the «git» user.

You should verify your connection by typing:

$ ssh -T git@github.com
> Hi USERNAME! You've successfully authenticated...

Make sure you have a key that is being used

  1. Open TerminalTerminalGit Bash.
  2. Verify that you have a private key generated and loaded into SSH.
    # start the ssh-agent in the background
    $ eval "$(ssh-agent -s)"
    > Agent pid 59566
    $ ssh-add -l -E sha256
    > 2048 SHA256:274ffWxgaxq/tSINAykStUL7XWyRNcRTlcST1Ei7gBQ /Users/USERNAME/.ssh/id_rsa (RSA)

If you have GitHub Desktop installed, you can use it to clone repositories and not deal with SSH keys.

  1. If you are using Git Bash, turn on ssh-agent:

    # start the ssh-agent in the background
    $ eval "$(ssh-agent -s)"
    > Agent pid 59566

    If you are using another terminal prompt, such as Git for Windows, turn on ssh-agent:

    # start the ssh-agent in the background
    $ eval $(ssh-agent -s)
    > Agent pid 59566
  2. Verify that you have a private key generated and loaded into SSH.

    $ ssh-add -l -E sha256
    > 2048 SHA256:274ffWxgaxq/tSINAykStUL7XWyRNcRTlcST1Ei7gBQ /Users/USERNAME/.ssh/id_rsa (RSA)
  1. Open TerminalTerminalGit Bash.
  2. Verify that you have a private key generated and loaded into SSH.
    $ ssh-add -l -E sha256
    > 2048 SHA256:274ffWxgaxq/tSINAykStUL7XWyRNcRTlcST1Ei7gBQ /Users/USERNAME/.ssh/id_rsa (RSA)

The ssh-add command should print out a long string of numbers and letters. If it does not print anything, you will need to generate a new SSH key and associate it with GitHub.

Tip: On most systems the default private keys (~/.ssh/id_rsa and ~/.ssh/identity) are automatically added to the SSH authentication agent. You shouldn’t need to run ssh-add path/to/key unless you override the file name when you generate a key.

Getting more details

You can also check that the key is being used by trying to connect to git@github.com:

$ ssh -vT git@github.com
> ...
> debug1: identity file /Users/YOU/.ssh/id_rsa type -1
> debug1: identity file /Users/YOU/.ssh/id_rsa-cert type -1
> debug1: identity file /Users/YOU/.ssh/id_dsa type -1
> debug1: identity file /Users/YOU/.ssh/id_dsa-cert type -1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Trying private key: /Users/YOU/.ssh/id_rsa
> debug1: Trying private key: /Users/YOU/.ssh/id_dsa
> debug1: No more authentication methods to try.
> Permission denied (publickey).

In that example, we did not have any keys for SSH to use. The «-1» at the end of the «identity file» lines means SSH couldn’t find a file to use. Later on, the «Trying private key» lines also indicate that no file was found. If a file existed, those lines would be «1» and «Offering public key», respectively:

$ ssh -vT git@github.com
> ...
> debug1: identity file /Users/YOU/.ssh/id_rsa type 1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Offering RSA public key: /Users/YOU/.ssh/id_rsa

Verify the public key is attached to your account

You must provide your public key to GitHub to establish a secure connection.

  1. Open Terminal.

  2. Start SSH agent in the background.

    $ eval "$(ssh-agent -s)"
    > Agent pid 59566
  3. Find and take a note of your public key fingerprint.

    $ ssh-add -l -E sha256
    > 2048 SHA256:274ffWxgaxq/tSINAykStUL7XWyRNcRTlcST1Ei7gBQ /Users/USERNAME/.ssh/id_rsa (RSA)
  4. In the upper-right corner of any page, click your profile photo, then click Settings.

    Settings icon in the user bar

  5. In the «Access» section of the sidebar, click SSH and GPG keys.

  6. Compare the list of SSH keys with the output from the ssh-add command.
    SSH key listing in GitHub

  1. Open the command line.

  2. Start SSH agent in the background.

    $ ssh-agent -s
    > Agent pid 59566
  3. Find and take a note of your public key fingerprint.

    $ ssh-add -l -E sha256
    > 2048 SHA256:274ffWxgaxq/tSINAykStUL7XWyRNcRTlcST1Ei7gBQ /Users/USERNAME/.ssh/id_rsa (RSA)
  4. In the upper-right corner of any page, click your profile photo, then click Settings.

    Settings icon in the user bar

  5. In the «Access» section of the sidebar, click SSH and GPG keys.

  6. Compare the list of SSH keys with the output from the ssh-add command.
    SSH key listing in GitHub

  1. Open Terminal.

  2. Start SSH agent in the background.

    $ eval "$(ssh-agent -s)"
    > Agent pid 59566
  3. Find and take a note of your public key fingerprint. If you’re using OpenSSH 6.7 or older:

    $ ssh-add -l
    > 2048 a0:dd:42:3c:5a:9d:e4:2a:21:52:4e:78:07:6e:c8:4d /Users/USERNAME/.ssh/id_rsa (RSA)

    If you’re using OpenSSH 6.8 or newer:

    $ ssh-add -l -E md5
    > 2048 MD5:a0:dd:42:3c:5a:9d:e4:2a:21:52:4e:78:07:6e:c8:4d /Users/USERNAME/.ssh/id_rsa (RSA)
  4. In the upper-right corner of any page, click your profile photo, then click Settings.

    Settings icon in the user bar

  5. In the «Access» section of the sidebar, click SSH and GPG keys.

  6. Compare the list of SSH keys with the output from the ssh-add command.
    SSH key listing in GitHub

If you don’t see your public key in GitHub, you’ll need to add your SSH key to GitHub to associate it with your computer.

Warning: If you see an SSH key you’re not familiar with on GitHub, delete it immediately and contact GitHub Support, for further help. An unidentified public key may indicate a possible security concern. For more information, see «Reviewing your SSH keys.»

GitHub ‘Permission denied (publickey)’ error

If your attempt to clone a GitHub repository over SSH is foiled by GitHub’s Permission denied (publickey) SSH error, there’s usually a quick fix.

GitHub’s Permission denied (publickey) error is usually caused by one of the following three issues:

  1. You have used an incorrect email address in the GitHub SSH URL
  2. You have not configured your public SSH key in your GitHub account
  3. You must create GitHub SSH keys to be used by the secure shell

Always use [email protected]

An SSH URL for my rock-paper-scissors repository looks like this:

[email protected]:cameronmcnz/rock-paper-scissors.git

The preamble of the SSH URL must be [email protected] Some users incorrectly use their GitHub account email, or substitute their username where the first git is.

Do not change the email address. It must be: [email protected]

Git SSH Keys Tutorials

Further your knowledge with these Git and SSH tutorials:

  • See how to  Generate SSH keys for GitHub
  • Work with the SSH KeyGen tool for GitHub
  • Learn to setup GitHub SSH Keys
  • Use SSH with GitHub on Windows machines
  • Use Git to clone GitHub with SSH
  • Use GitLab? Then  config GitLab SSH Keys
  • Use Atlassian? Learn to use BitBucket and SSH

Follow these tutorials and you’ll learn GitHub Actions fast.

You can test the GitHub SSH connection for the Permission denied error by using the -T switch. If SSH is set up correctly, the output includes a reference to your username:

C:fixpermissiondenied> ssh -T [email protected]
Hi cameronmcnz! 
GitHub SSH authentication is successful...

GitHub SSH configuration

Your public SSH key must be registered in your account setting in order to avoid GitHub’s Permission denied (publickey) SSH error.

Confirm that your public key has been configured correctly by checking the SSH and GPG link in your account settings. If no keys are listed, add your public key and try to connect to GitHub over SSH again. The error should go away.

setup github ssh key

If you don’t register your public key in the admin console, you will definitely encounter GitHub’s Permission denied (publickey) error with SSH.

GitHub SSH key generation

One sure fire way to guarantee you’ll see GitHub’s Permission denied (publickey) error is if you don’t have any SSH keys at all.

Check for the .ssh folder under the user’s home directory. Regardless of whether you run on Windows or Linux, there should be a public and private key file in this folder. If it is empty, you’ll need to create an SSH keypair and then register the public key in GitHub.

C:fixpermissiondenied> ssh-keygen -o -t rsa -C "[email protected]"

Once the GitHub SSH keys are created, copy the value of the public key and configure it in your GitHub account settings. Then attempt to SSH to GitHub again.

It’s always frustrating when you encounter an error, especially when it’s your first time connecting to a remote resource. Fortunately, if you’ve hit GitHub’s Permission denied (publickey) SSH error, follow one of the three resolutions suggested above and that should fix the problem.

Should the sudo command or elevated privileges be used with Git?

You should not be using the sudo command or elevated privileges, such as administrator permissions, with Git. If you have a very good reason you must use sudo, then ensure you are using it with every command (it’s probably just better to use su to get a shell as root at that point). If you generate SSH keys without sudo and then try to use a command like sudo git push, you won’t be using the same keys that you generated.

Check that you are connecting to the correct server

Typing is hard, we all know it. Pay attention to what you type; you won’t be able to connect to «githib.com» or «guthub.com». In some cases, a corporate network may cause issues resolving the DNS record as well.

To make sure you are connecting to the right domain, you can enter the following command:

$ ssh -vT git@HOSTNAME
> OpenSSH_8.1p1, LibreSSL 2.7.3
> debug1: Reading configuration data /Users/YOU/.ssh/config
> debug1: Reading configuration data /etc/ssh/ssh_config
> debug1: /etc/ssh/ssh_config line 47: Applying options for *
> debug1: Connecting to HOSTNAME port 22.

The connection should be made on port 22.

Always use the «git» user

All connections, including those for remote URLs, must be made as the «git» user. If you try to connect with your GitHub AE username, it will fail:

$ ssh -T GITHUB-USERNAME@HOSTNAME
> Permission denied (publickey).

If your connection failed and you’re using a remote URL with your GitHub AE username, you can change the remote URL to use the «git» user.

You should verify your connection by typing:

$ ssh -T git@HOSTNAME
> Hi USERNAME! You've successfully authenticated...

Make sure you have a key that is being used

  1. Open TerminalTerminalGit Bash.
  2. Verify that you have a private key generated and loaded into SSH.
    # start the ssh-agent in the background
    $ eval "$(ssh-agent -s)"
    > Agent pid 59566
    $ ssh-add -l -E sha256
    > 2048 SHA256:274ffWxgaxq/tSINAykStUL7XWyRNcRTlcST1Ei7gBQ /Users/USERNAME/.ssh/id_rsa (RSA)

If you have GitHub Desktop installed, you can use it to clone repositories and not deal with SSH keys.

  1. If you are using Git Bash, turn on ssh-agent:

    # start the ssh-agent in the background
    $ eval "$(ssh-agent -s)"
    > Agent pid 59566

    If you are using another terminal prompt, such as Git for Windows, turn on ssh-agent:

    # start the ssh-agent in the background
    $ eval $(ssh-agent -s)
    > Agent pid 59566
  2. Verify that you have a private key generated and loaded into SSH.

    $ ssh-add -l -E sha256
    > 2048 SHA256:274ffWxgaxq/tSINAykStUL7XWyRNcRTlcST1Ei7gBQ /Users/USERNAME/.ssh/id_rsa (RSA)
  1. Open TerminalTerminalGit Bash.
  2. Verify that you have a private key generated and loaded into SSH.
    $ ssh-add -l -E sha256
    > 2048 SHA256:274ffWxgaxq/tSINAykStUL7XWyRNcRTlcST1Ei7gBQ /Users/USERNAME/.ssh/id_rsa (RSA)

The ssh-add command should print out a long string of numbers and letters. If it does not print anything, you will need to generate a new SSH key and associate it with GitHub AE.

Tip: On most systems the default private keys (~/.ssh/id_rsa and ~/.ssh/identity) are automatically added to the SSH authentication agent. You shouldn’t need to run ssh-add path/to/key unless you override the file name when you generate a key.

Getting more details

You can also check that the key is being used by trying to connect to git@[hostname]:

$ ssh -vT git@HOSTNAME
> ...
> debug1: identity file /Users/YOU/.ssh/id_rsa type -1
> debug1: identity file /Users/YOU/.ssh/id_rsa-cert type -1
> debug1: identity file /Users/YOU/.ssh/id_dsa type -1
> debug1: identity file /Users/YOU/.ssh/id_dsa-cert type -1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Trying private key: /Users/YOU/.ssh/id_rsa
> debug1: Trying private key: /Users/YOU/.ssh/id_dsa
> debug1: No more authentication methods to try.
> Permission denied (publickey).

In that example, we did not have any keys for SSH to use. The «-1» at the end of the «identity file» lines means SSH couldn’t find a file to use. Later on, the «Trying private key» lines also indicate that no file was found. If a file existed, those lines would be «1» and «Offering public key», respectively:

$ ssh -vT git@HOSTNAME
> ...
> debug1: identity file /Users/YOU/.ssh/id_rsa type 1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Offering RSA public key: /Users/YOU/.ssh/id_rsa

Verify the public key is attached to your account

You must provide your public key to GitHub AE to establish a secure connection.

  1. Open Terminal.

  2. Start SSH agent in the background.

    $ eval "$(ssh-agent -s)"
    > Agent pid 59566
  3. Find and take a note of your public key fingerprint.

    $ ssh-add -l -E sha256
    > 2048 SHA256:274ffWxgaxq/tSINAykStUL7XWyRNcRTlcST1Ei7gBQ /Users/USERNAME/.ssh/id_rsa (RSA)
  4. In the upper-right corner of any page, click your profile photo, then click Settings.

    Settings icon in the user bar

  5. In the user settings sidebar, click SSH and GPG keys.
    Authentication keys

  6. Compare the list of SSH keys with the output from the ssh-add command.
    SSH key listing in GitHub AE

  1. Open the command line.

  2. Start SSH agent in the background.

    $ ssh-agent -s
    > Agent pid 59566
  3. Find and take a note of your public key fingerprint.

    $ ssh-add -l -E sha256
    > 2048 SHA256:274ffWxgaxq/tSINAykStUL7XWyRNcRTlcST1Ei7gBQ /Users/USERNAME/.ssh/id_rsa (RSA)
  4. In the upper-right corner of any page, click your profile photo, then click Settings.

    Settings icon in the user bar

  5. In the user settings sidebar, click SSH and GPG keys.
    Authentication keys

  6. Compare the list of SSH keys with the output from the ssh-add command.
    SSH key listing in GitHub AE

  1. Open Terminal.

  2. Start SSH agent in the background.

    $ eval "$(ssh-agent -s)"
    > Agent pid 59566
  3. Find and take a note of your public key fingerprint. If you’re using OpenSSH 6.7 or older:

    $ ssh-add -l
    > 2048 a0:dd:42:3c:5a:9d:e4:2a:21:52:4e:78:07:6e:c8:4d /Users/USERNAME/.ssh/id_rsa (RSA)

    If you’re using OpenSSH 6.8 or newer:

    $ ssh-add -l -E md5
    > 2048 MD5:a0:dd:42:3c:5a:9d:e4:2a:21:52:4e:78:07:6e:c8:4d /Users/USERNAME/.ssh/id_rsa (RSA)
  4. In the upper-right corner of any page, click your profile photo, then click Settings.

    Settings icon in the user bar

  5. In the user settings sidebar, click SSH and GPG keys.
    Authentication keys

  6. Compare the list of SSH keys with the output from the ssh-add command.
    SSH key listing in GitHub AE

If you don’t see your public key in GitHub AE, you’ll need to add your SSH key to GitHub AE to associate it with your computer.

Warning: If you see an SSH key you’re not familiar with on GitHub AE, delete it immediately and contact your enterprise owner, for further help. An unidentified public key may indicate a possible security concern. For more information, see «Reviewing your SSH keys.»

GitHub is a code hosting platform for version control and collaboration allowing you to work together with other developers from all over the world building software. Let’s say you are starting on this journey and have a personal repository you are trying to perform a git clone or a git push but end up receiving obscure permission denied publickey error. Worry no more, this article will share how to fix this error once and for all.

The Error Message

For instance, when you are running a git clone command, you are seeing an error messaging that goes something like below.

Cloning into '<YOUR FOLDER>'...
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.

If you are cloning a git repository using Visual Studio, you might be seeing this error message below which is very obscure and at least to me, not very helpful.

Git failed with a fatal error.
Could not read from remote repository.

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

If you are seeing any of the above error messages or other messages that relate to could not read from a remote repository, or permission denied (publickey) then read along to learn how to fix this.

Fixing Git Permission Denied PublicKey

After trying many different possible solutions such as re-installing Github desktop, deleting the Visual Studio git folder, and many other solutions that worked for others online, but not for me, the following is the only solution that fixed this issue for me.

Install Open SSH Client

The first step to solve this issue is to generate an SSH key pair that will be later loaded to your GitHub account. On windows, this is very easy to do with the Open-SSH client. To install it head on to your windows settings optional features.

Install Open-SSH

Then install the OpenSSH Client that you see below.

Generate SSH Key Pair

With the OpenSSH Client install you can now use it to generate an SSH Key Pair. Open command prompt as an administrator and type the following:

ssh-keygen

To keep it very simple, just hit ENTER for all that you are prompted. When finished, you should see something like below. I have obscured a few of the items below.

Generate SSH Key Pair

You should also notice in the message where the keys got generated. This location will be used in the following step.

Copy SSH Key To GitHub

To get the key, you need to navigate to the folder where the keys got generated within the command prompt. Once there, type the following command, assuming id_rsa.pub is the filename and that you are using windows, for Linux it will be the cat command instead.

type id_rsa.pub
SSH Key to Github

Now head on to your GitHub account into the settings.

SSH Key Github
Github SSH

Click where you see New SSH Key and copy the whole string that starts with ssh-rsa into here with an adequate name. Once you do this, git clone or git push will begin to work as expected!

Conclusion

I hope this article has helped you fix this permission denied publickey error and that you are finally able to clone a git repository or begin pushing code changes to one of them.

Stuck with permission denied in publickey ssh github? We can help you.

As part of our Server Management Services, we assist our customers with several github queries.

Today, let us see how our techs proceed to resolve it.

Permission denied in publickey ssh github

Typical error might look as shown below:

username@github.com: Permission denied (public key).
fatal: Could not read from remote repository.

It means GitHub is rejecting your connection because it is your private repo.

GitHub does not trust your computer because it does not have the public key of your computer.

Today, let us see the steps followed by our Support Techs to resolve it. 

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

Step 1:

Firstly, create SSH key pair

One of the easiest ways for you to generate a key pair is by running ssh-keygen utility.

Open the command prompt and type in the following

ssh-keygen

To keep the ssh-keygen simple, do not enter any key name or passphrase.

Step 2:

Adding SSH key to your GitHub account

1. Firstly, goto your GitHub Account -> Settings

2. Then, look for SSH and GPG keys under **Account Settings -> SSH and GPG keys **

3. After that click on New SSH Key. Assign some meaningful name to your key

4. To get the key goto to your command prompt and switch directory path

5. Then, run the following command

cat id_rsa.pub

6. Then, copy the content of the key

7. Finally, aste the key inside your GitHub account

[Stuck in between? We’d be glad to assist you]

Conclusion

In short, today we saw how our Support Techs assist in resolving

Stuck with permission denied in publickey ssh github? We can help you.

As part of our Server Management Services, we assist our customers with several github queries.

Today, let us see how our techs proceed to resolve it.

Permission denied in publickey ssh github

Typical error might look as shown below:

username@github.com: Permission denied (public key).
fatal: Could not read from remote repository.

It means GitHub is rejecting your connection because it is your private repo.

GitHub does not trust your computer because it does not have the public key of your computer.

Today, let us see the steps followed by our Support Techs to resolve it. 

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

Step 1:

Firstly, create SSH key pair

One of the easiest ways for you to generate a key pair is by running ssh-keygen utility.

Open the command prompt and type in the following

ssh-keygen

To keep the ssh-keygen simple, do not enter any key name or passphrase.

Step 2:

Adding SSH key to your GitHub account

1. Firstly, goto your GitHub Account -> Settings

2. Then, look for SSH and GPG keys under **Account Settings -> SSH and GPG keys **

3. After that click on New SSH Key. Assign some meaningful name to your key

4. To get the key goto to your command prompt and switch directory path

5. Then, run the following command

cat id_rsa.pub

6. Then, copy the content of the key

7. Finally, aste the key inside your GitHub account

[Stuck in between? We’d be glad to assist you]

Conclusion

In short, today we saw how our Support Techs assist in resolving

Stuck with permission denied in publickey ssh github? We can help you.

As part of our Server Management Services, we assist our customers with several github queries.

Today, let us see how our techs proceed to resolve it.

Permission denied in publickey ssh github

Typical error might look as shown below:

username@github.com: Permission denied (public key).
fatal: Could not read from remote repository.

It means GitHub is rejecting your connection because it is your private repo.

GitHub does not trust your computer because it does not have the public key of your computer.

Today, let us see the steps followed by our Support Techs to resolve it. 

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

Step 1:

Firstly, create SSH key pair

One of the easiest ways for you to generate a key pair is by running ssh-keygen utility.

Open the command prompt and type in the following:

ssh-keygen

To keep the ssh-keygen simple, do not enter any key name or passphrase.

Step 2:

Adding SSH key to your GitHub account

1. Firstly, goto your GitHub Account -> Settings

2. Then, look for SSH and GPG keys under **Account Settings -> SSH and GPG keys **

3. After that click on New SSH Key. Assign some meaningful name to your key

4. To get the key goto to your command prompt and switch directory path

5. Then, run the following command

cat id_rsa.pub

6. Then, copy the content of the key

7. Finally, aste the key inside your GitHub account

[Stuck in between? We’d be glad to assist you]

Conclusion

In short, today we saw how our Support Techs assist in resolving permission denied in publickey ssh github.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

Понравилась статья? Поделить с друзьями:
  • Error permission denied errno 13 permission denied
  • Error page you have encountered an unexpected error please contact the system administrator for assistance
  • Error page text
  • Error page not found the requested url was not found on this server
  • Error page jsp