17

I have just create a git repository on my iMac under the user git account and am now want to clone it from my main user account on the same computer. I have created my SSH key and added it to the .ssh/authorized_keys file. However when I log back in with my main account I get the following error message:

Permission denied (publickey) fatal: The remote end hung up unexpectedly

Now to me, and while searching on the web it seems like my public key is incorrect. I have created it twice and still get the same issue.

Brian Webster
  • 30,033
  • 48
  • 152
  • 225
flowy
  • 482
  • 2
  • 6
  • 15
  • Note that your (2nd) local clone will only see the local branches of the 1st local repo. It will _not_ see any remote branches of the latter, unless you also add the remote of the 1st repo to the list of remotes of the 2nd repo — one remote for the 1st local repo and one 'truly' remote for the repo not-on-mac. Stashes also won't be in the 2nd repo. If you want to have the same remote, stash, git config etc. etc. you might want to just copy the 1st repo directory. – PDK Jul 07 '22 at 14:09

3 Answers3

43

You shouldn't need an ssh key at all. Make all of the files world readable and just clone the full path. In other words, do

$ git clone /path/to/repo
William Pursell
  • 204,365
  • 48
  • 270
  • 300
18
git clone /path/to_repository  /path/to_where_you_want_it_cloned

Make sure that your main user account has permissions to copy to/from your accounts directories.

Braiam
  • 1
  • 11
  • 47
  • 78
HBlend
  • 545
  • 1
  • 3
  • 13
0

One additional point is that if you created the git repo and did a git init -bare, you use a .git extension, but you do not need this on the folder name (when cloning it on the same machine).

mrwonderfulness
  • 361
  • 2
  • 7