Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SourceTree always Permission denied (publickey)

i use soureTree for clone ssh project.

  1. i've already created ssh key
  2. i've already set up gitlab ssh key setting
  3. i've ssh-add "mysshkey"
  4. i've ssh-add -K 'mysshkey'

when i print ssh -T ,i can make it success in the command line. when i git clone, pull ,push in ssh ways...It still works in the command line.(terminal)

but in sourcetree still get error now:

Permission denied (publickey)

how can i solve it?

like image 383
Frankie_0927 Avatar asked Aug 02 '18 09:08

Frankie_0927


People also ask

How do I remove permissions denied Publickey?

Solution 1: Enable Password Authentication In the file, find the PasswordAuthentication line and make sure it ends with yes . Find the ChallengeResponseAuthentication option and disable it by adding no . If lines are commented out, remove the hash sign # to uncomment them. Save the file and exit.

Why do I get permission denied Publickey?

"Permission denied (publickey)" and "Authentication failed, permission denied" errors occur if: You're trying to connect using the wrong user name for your AMI. The file permissions within the operating system are incorrect on the instance. The incorrect SSH public key (.

How do I fix Git GitHub Permission denied Publickey fatal could not read from remote repository?

The “Permission denied (publickey). fatal: Could not read from remote repository” error is caused by an issue with the way in which you authenticate with a Git repository. To solve this error, make sure your key is being used on your Git account. If it is not, add your key to Git.

How do I add a SSH key to Sourcetree?

From Sourcetree, open the PuTTY Key Generator dialog by going to Tools > Create or Import SSH Keys. Click Load, navigate to your SSH folder, and click the private key. Make sure you're looking at All files if you don't see your private key. Enter your passphrase for the SSH key and click OK.


2 Answers

I downloaded SourceTree 2.7.6 and encountered same problem. I think @Frankie_0927 are right, private key must be named id_rsa and must be registered in ssh agent.

for other people encountered this problem: try generate a pair of key following the instructions in below link: https://help.github.com/articles/connecting-to-github-with-ssh/ store the private key id_rsa in ~/user/YOURUSERNAME/.ssh (path for mac) and post public key in github account. then run

ssh-add -l

you will see

The agent has no identities.

so you run

ssh-add -K ~/.ssh/id_rsa

to add the key into ssh agent. after this, run

ssh-add -l

again, you will see the key is added and the problem should be solved.

like image 84
bubuStar Avatar answered Sep 19 '22 09:09

bubuStar


You are receiving this message because it could not authenticate you with any of the keys that were offered to it by your SSH agent. To verify this is the case, do the following:

ssh -T 

This will attempt to create a connection to it for Mercurial. You should receive a response similar to the following if your key is correctly loaded.

If you do not see a message,this can be caused by a couple of factors, but these are the most common:

- Your public key isn't loaded

To check to see if your public key is loaded, do the following:

  1. Open a browser and log into origin.

  2. The SSH Keys page displays. It shows a list of any existing keys.

  3. If you do not have any keys listed,set one up.

- Your identity isn't loaded into your SSH Agent

If your SSH agent doesn't know to offer a key, the connection will fail. To find out what keys your SSH Agent currently is offering, and add them, do the following:

$ ssh-add -l

Then, if you don't see your key listed, add it by 

ssh-add ~/.ssh/identity

For more information, check out our full Troubleshoot SSH issues guide.

- You do not have permission to create the repository on your local filesystem

If you get the error "Permission denied", it is also possible that git or mercurial doesn't have permission to create the project folder locally. Check permissions for the directory where you're attempting to check out the project, and make sure you have write access.

1   Right click and "Run as Administrator".
2   Type ssh-keygen
3   Press enter.
4   It will ask you to save the key to the specific directory.
5   Press enter. It will prompt you to type password or enter without password.
6   The public key will be created to the specific directory.
7   Now go to the directory and open .ssh folder.
8   You'll see a file id_rsa.pub. Open it on notepad. Copy all text from it.
9   Go to https://gitlab.com/profile/keys .
10  Paste here in the "key" textfield.
11  Now click on the "Title" below. It will automatically get filled.
12  Then click "Add key".

Found that inside /var/log/gitlab/sshd/current there were multiple occurences of a message: Authentication refused: bad ownership or modes for file /var/opt/gitlab/.ssh/authorized_keys After which I changed ownership of that file from 99:users to git:users with: chown git:users authorized_keys

like image 32
Saige Zhang Avatar answered Sep 18 '22 09:09

Saige Zhang