r/github • • 1d ago

Question Setting up SSH

I'm on Linux MX and I'm having trouble connecting my computer to my repos, to clone and what-not.

I think I'm following the guide on it. I want to use GitFiend to manage my projects, but using got in the command line it first throws an key authentication error and asks if I want to continue anyway. I say yes and it creates a "known_hosts" file, but then throws a permission denied error.

I can't tell what I'm doing wrong. These were my steps:

1 - Created a ~/.ssh directory

2 - ssh-keygen -t ed25519 -C "teclo+teal@disroot.org"
Inserted "github" as the key file names and left without password (also tried my password for Github on other attempts)

3 - eval "$(ssh-agent -s)"

4 - ssh-add github

5 - ssh-add -L and echo "$SSH_AUTH_SOCK" as just checks, but they didn't seem to say anything I could recognize as a problem.

6 - created ~/.ssh/config and added

Host git@github.com
   ForwardAgent yes

7 - Opened ~/.profile and added ssh-add ~/.ssh/github

8 - The text in ~/.ssh/github.pub is added to GitHub.

0 Upvotes

8 comments sorted by

3

u/andeeeeeeeeer 1d ago edited 1d ago

I think it's your ~/.ssh/config. Host matches the hostname you connect to, so "Host git@github.com" never matches anything.

Change it to:

```
Host github.com
IdentityFile ~/.ssh/github
IdentitiesOnly yes
```

and drop the ForwardAgent line, you don't need it. Since you named the key "github" instead of id_ed25519, ssh won't pick it up on its own, that's why the config matters. Also check the key actually landed in ~/.ssh and not in whatever folder you ran ssh-keygen from. Then test with ssh -T git@github.com before going back to GitFiend.

1

u/Sal_Iko 1d ago

Thank you! That seems to be the problem. Just to be clear, after doing the correction, I tried cloning with the git command and got this ("Wicked Haywire" is one of my projects):

Cloning into 'Wicked_Haywire'...
The authenticity of host 'github.com (20.250.119.67)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

I replied "yes" and this came up:

Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
remote: Enumerating objects: 1236, done.
remote: Counting objects: 100% (346/346), done.
remote: Compressing objects: 100% (179/179), done.
remote: Total 1236 (delta 198), reused 263 (delta 135), pack-reused 890 (from 1)
Receiving objects: 100% (1236/1236), 3.04 MiB | 402.00 KiB/s, done.
Resolving deltas: 100% (709/709), done.

But GitFiend can now access my repos fine, so far.

2

u/ImDevinC 1d ago

-1

u/Sal_Iko 1d ago edited 1d ago

These are the steps I did. Probably should have mentioned in the OP, but I'm frustrated and been around this for hours:
1 - Created a ~/.ssh directory

2 - ssh-keygen -t ed25519 -C "teclo+teal@disroot.org"
Inserted "github" as the key file names and left without password (also tried my password for Github on other attempts)

3 - eval "$(ssh-agent -s)"

4 - ssh-add github

5 - ssh-add -L and echo "$SSH_AUTH_SOCK" as just checks, but they didn't seem to say anything I could recognize as a problem.

6 - created ~/.ssh/config and added

Host git@github.com
ForwardAgent yes

7 - Opened ~/.profile and added ssh-add ~/.ssh/github

8 - The text in ~/.ssh/github.pub is added to GitHub.

If using the command line Git to clone, it shows this:

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

2

u/Teleconferences 1d ago

It’s 5 AM and I’m on my phone, but I swear your host in your .ssh/config is wrong and should just be “github.com” not “git@github.com”

2

u/Sal_Iko 1d ago

Yes, you are half right. Someone else gave me a complete solution and the problem was indeed the "config" file. Thank you.

3

u/houseoftrees_ 1d ago

lol learn the basics before downloading whatever the fuck Gitfiend is, god my heart weeps for society

1

u/SlowPlan8945 1d ago

You have two small issues in your setup causing the Permission denied (publickey) error:

1. Your ~/.ssh/config syntax is wrong In Step 6, Host takes the domain name, not user@domain, and you didn't tell SSH which key file to use (since it's named github instead of the default id_ed25519).

Replace your ~/.ssh/config contents with:

Code snippet

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/github
  IdentitiesOnly yes

2. Check where you ran Step 2 & 4 In Step 2, typing "github" without a full path creates ./github in whatever directory your terminal was currently in, rather than ~/.ssh/github. Make sure both github and github.pub actually live inside ~/.ssh/:

Bash

mv ~/github* ~/.ssh/ 2>/dev/null
chmod 700 ~/.ssh
chmod 600 ~/.ssh/github
chmod 644 ~/.ssh/github.pub

(Note: That initial authenticity prompt asking if you want to continue connecting is normal on your first connection to GitHub—you didn't do anything wrong there.)

Test it: Run ssh -T git@github.com. If it says Hi <username>! You've successfully authenticated..., you're good to go. (You can also remove ssh-add from ~/.profile once IdentityFile is in your config, as SSH will load it automatically.)You have two small issues in your setup causing the Permission denied (publickey) error:1. Your ~/.ssh/config syntax is wrong
In Step 6, Host takes the domain name, not user@domain, and you didn't tell SSH which key file to use (since it's named github instead of the default id_ed25519).Replace your ~/.ssh/config contents with:Code snippet
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/github
IdentitiesOnly yes
2. Check where you ran Step 2 & 4
In Step 2, typing "github" without a full path creates ./github in whatever directory your terminal was currently in, rather than ~/.ssh/github. Make sure both github and github.pub actually live inside ~/.ssh/:Bash
mv ~/github* ~/.ssh/ 2>/dev/null
chmod 700 ~/.ssh
chmod 600 ~/.ssh/github
chmod 644 ~/.ssh/github.pub
(Note: That initial authenticity prompt asking if you want to continue connecting is normal on your first connection to GitHub—you didn't do anything wrong there.)Test it:
Run ssh -T git@github.com. If it says Hi <username>! You've successfully authenticated..., you're good to go. (You can also remove ssh-add from ~/.profile once IdentityFile is in your config, as SSH will load it automatically.)