Ssh failure: permission denied (publickey)

Hi,

I feel like this is such an easy issue to fix but I just couldn’t figure it out. So please help!

I just wanted to enable my normal git workflow on both GitHub and GitLab. I’ve already generated/added my ssh keys and stored those in GitHub/GitLab. However, every time I want to connect using ssh (operations like git push) I always get this error:

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.

Although I’m pretty sure all my ssh keys exist and already added. I would need to do this every time to enable ssh connection:

$ eval "$(ssh-agent -s)"
$ sh-add ~/.ssh/github_id_ed25519

which is super annoying. Any idea how to fix this?

ssh-related configuration.nix:

  programs.ssh.startAgent = true;

  services.openssh.enable = true;

Thank you!

As this is not a default name for a key file and therefore won’t be used automatically, how does your SSH configuration look like? Did you tell SSH to use those keys for GitHub.com/GitLab.com?

Here is the relevant section of my configuration:

Host github.com
  IdentityFile ~/.ssh/github
Host gitlab.com
  AddressFamily inet
  IdentityFile ~/.ssh/gitlab
1 Like