Asked  7 Months ago    Answers:  5   Viewed   84 times

I'm on Mac Snow Leopard and I just installed git.

I just tried

git clone git@thechaw.com:cakebook.git

but that gives me this error:

Initialized empty Git repository in `/Users/username/Documents/cakebook/.git/`
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

What am I missing?
I've also tried doing ssh-keygen with no passphase but still same error.

 Answers

87

If the user has not generated a ssh public/private key pair set before

This info is working on theChaw but can be applied to all other git repositories which support SSH pubkey authentications. (See gitolite, gitlab or github for example.)

First start by setting up your own public/private key pair set. This can use either DSA or RSA, so basically any key you setup will work. On most systems you can use ssh-keygen.

  • First you'll want to cd into your .ssh directory. Open up the terminal and run:

    cd ~/.ssh && ssh-keygen

  • Next you need to copy this to your clipboard.
    • On OS X run: cat id_rsa.pub | pbcopy
    • On Linux run: cat id_rsa.pub | xclip
    • On Windows (via Cygwin/Git Bash) run: cat id_rsa.pub | clip
  • Add your key to your account via the website.
  • Finally setup your .gitconfig.
    • git config --global user.name "bob"
    • git config --global user.email bob@... (don't forget to restart your command line to make sure the config is reloaded)

That's it you should be good to clone and checkout.

Further information can be found at https://help.github.com/articles/generating-ssh-keys (thanks to @Lee Whitney) -

If the user has generated a ssh public/private key pair set before

  • check which key have been authorized on your github or gitlab account settings
  • determine which corresponding private key must be associated from your local computer

eval $(ssh-agent -s)

  • define where the keys are located

ssh-add ~/.ssh/id_rsa

Tuesday, June 1, 2021
 
RompelStompel
answered 7 Months ago
49

The error in this case was that the keys were generated by the root user, but they need to be accessible by the web server group/owner www-data.

I didn't like the idea of keeping ssh keys in a web folder open to www-data, so I moved the key files to a new user's home directory (/home/keyuser/) then made them accessible to www-data. Authentication was successful.

Even though the original error was saying it found the file, it couldn't read the file.

A better debug method is to try reading the file via php:

$prv_key = file_get_contents('/var/www/application/files/id_dsa');
print "<pre>";
var_export($prv_key);
print "</pre>";
Saturday, May 29, 2021
 
Shobit
answered 7 Months ago
34

The key could be already in use on other github projects as deploy key, that's a bit tricky to find but run:

ssh -T -ai ~/.ssh/id_rsa git@github.com

to find the used key, delete it and then readd it again in the right user/repo. that was very useful for me

from: https://help.github.com/articles/error-key-already-in-use/#finding-where-the-key-has-been-used


edit: as pointed out by @mikhail-morgunov, this doesn't works all the time, you should really use this snippet only if the default id_rsa SSH private key is your github's default one

this is a snippet where the key name has been extracted:

ssh -T -ai ~/.ssh/KEY_NAME git@github.com

change KEY_NAME with the name of your SSH private key and you will be good to go

Friday, September 3, 2021
 
Success Man
answered 3 Months ago
47

So as mentioned in prior answers, the Permission denied error in Windows is because you are trying to use a key other than id_rsa.

Windows lacks the bells and whistles that Linux and Mac have to try out all your public keys when trying to connect to a server via SSH. If you're using the ssh command, you can tell it which key to use by passing the -i flag followed by the path to the key to use:

ssh -i ~/.ssh/moovweb_rsa moov@git.moovweb.com

The above command should work just fine if you've uploaded moovweb_rsa.pub to the console (either via the moov login command or the console UI). However, trying any git related commands should fail because Git doesn't give you the ability to chose which key to use when connecting to the git remote. Because of this, SSH is forced to use the default key, id_rsa, and if that key doesn't work (or doesn't exist), then the connection fails with a permission denied error.

One possible solution, as suggested in other answers, is to simply rename your key to id_rsa. For most people, this is a fine solution. However, if you already have an id_rsa key and you would prefer to use a different key with Moovweb, you can edit your ~/.ssh/config file by adding the following contents:

Host git.moovweb.com
    IdentityFile ~/.ssh/moovweb_rsa

If you append the above lines to your ~/.ssh/config file (create it if it doesn't exist), you should be able to successfully get Git to communicate with the Moovweb remote git server. The config basically tells SSH that for the given host (git.moovweb.com), SSH should use the given key rather than the default.

It's worth nothing that this happens to all Git remotes; interactions with Github, Heroku, etc... also suffer through this problem in Windows. You could easily extend your ~/.ssh/config file to use separate SSH keys for each one of those services if you so desired:

Host git.moovweb.com
    IdentityFile ~/.ssh/moovweb_rsa

Host github.com
    IdentityFile ~/.ssh/github_rsa

Host heroku.com
    IdentityFile ~/.ssh/heroku_rsa
Monday, September 27, 2021
 
Lance
answered 3 Months ago
80

The only way I could find was disabling all the plugins altogether.

This stopped the error message. Now I'm enabling them back, one by one, so far so good.

Tuesday, September 28, 2021
 
Bitmap
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share