-1

in terminal I try to clone my git repository

git clone git@github.com:myuser/myrepository.git

The error message is:

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.

But I created a public key in github already. I tried once with id_ed1234.pub and also with id_rsa.pub.

(My local computer is a Mac and the server I like to clone to is a Linux)

The steps I made:

  1. in Terminal I created an ssh key:

    ssh-keygen -t ed25519 -C "myemail@example.com"

  2. I copied the content of /Users/myuser/.ssh/id_ed12345.pub.

  3. In the administration panel of my linux provider (shared host) I created a new public ssh key and pasted the content of id_ed12345.pub

  4. On github.com in settings I created an new ssh key and pasted the content of id_ed12345.pub

  5. in terminal I connected via ssh myuser@myhost, navigated to my folder.

  6. I made git init

  7. and made git clone git@github.com:myuser/myrepository.git

peace_love
  • 6,229
  • 11
  • 69
  • 157
  • It should work if you have correctly added your public key (by default id_rsa.pub) in GitHub. Can you share output of following command: `ls -alrt ~/.ssh/ ` – Manish Kapoor Aug 10 '22 at 09:51
  • @ManishKapoor Sure, see: https://codeshare.io/6pnD1g – peace_love Aug 10 '22 at 09:55
  • It looks fine. Can you try deleting regenerating fresh pair of keys after deleting the all the existing keys (`id_ed25519.pub, id_ed25519,id_rsa.pub, id_rsa`). And then uploading the contents of freshly generated public key. – Manish Kapoor Aug 10 '22 at 10:02
  • @ManishKapoor Thank you, I did everything you said. Still the same error message – peace_love Aug 10 '22 at 10:10
  • Show your steps, from "generate key" to "upload public key" to "run `ssh -Tv git@github.com` to test key". (Keep the *private* key secret of course, and feel free to obscure most of the public key bytes if you like.) – torek Aug 11 '22 at 00:54
  • @torek thank you, I tested your code and I get the message `Failed to add the host to the list of known hosts (coding/.ssh/known_hosts).` – peace_love Aug 11 '22 at 07:17
  • @torek also Hi peace_love! You've successfully authenticated, but GitHub does not provide shell access – peace_love Aug 11 '22 at 07:19
  • @torek these error messages only appear when I try `ssh -Tv git@github.com` on my local mac. When I first connect via ssh to the linux server, there are no error messages. Then it is like this: `debug1: Connection established.debug1: Authentications that can continue: publickey, debug1: No more authentication methods to try. git@github.com: Permission denied (publickey).` – peace_love Aug 11 '22 at 07:24
  • The "failed to add ..." message indicates that ssh doesn't have the ability (probably because of some permissions problem) to create or update the named `known_hosts` file. The subsequent "you've successfully authenticated" message means things are working. Meanwhile your Linux setup and output shows that you don't have any keys in place *on* your Linux machine, so that would explain why you can't get there from the Linux box. – torek Aug 11 '22 at 07:34
  • Note that if you're using an ssh *agent* (which is easy to do on a Mac, a little harder on Linux) you can have the agent forward the *private* key from your Mac laptop to the Linux machine, but you'll still need to install, on the Linux machine, the *public* key so that the Linux system can match it up and know to use it as the public key to go with that private key. – torek Aug 11 '22 at 07:35
  • In any case, when I said "show your steps", I mean **put this in the question**, where you can format it nicely and so on. Then everyone can read what you're doing much more easily. – torek Aug 11 '22 at 07:36
  • @torek I pasted every step I made into the question, can you check it? – peace_love Aug 11 '22 at 08:00
  • You say you're using two computers (a Mac and a Linux box) plus a third server (GitHub). You show generating a keypair, and copying it to GItHub. But you don't show copying it from your Linux box to your Mac, or vice versa (and your text description says that it works on your Mac so I assume you generated it on your Mac and did not copy it to your Linux box). That's your problem. – torek Aug 11 '22 at 08:02
  • Is it possible to clone not from git, but instead from my local mac directly to the server? Maybe that works? – peace_love Aug 11 '22 at 08:23

1 Answers1

1

You mention in comments that git clone git@github.com:myuser/myrepository.git already works! This means that you've done everything correctly.

Then, you mention in comments that you'd like to run this git clone command from a different computer:

the Linux server is a shared host, where I can only use an administration panel.

This is a completely different question. Consider closing the question you've asked so far, and asking instead—but first searching to see if there's already an answer—a question of the form "I can clone just fine using ssh from my macOS system to obtain a repository from GitHub, but now I need to clone the same repository to a Linux host on which I have ...". Fill in the "..." part with whatever limited access you do have, because that will set the parameters by which the process is possible, if it is possible. (If you have extremely limited access to some system, there may be things you cannot do at all on that system.)

torek
  • 448,244
  • 59
  • 642
  • 775