henriquehbr.xyz

Blog Supporters Resume
Part time open-sourcerer, Linux enthusiast, Rust fanatic

Custom-named SSH keys not working

September 25, 2021 — (Last edited on October 24, 2021)

Problem

By default, when trying to generate SSH keys with custom names (besides the default of id_ed25519) for multiple plataforms like GitHub, GitLab or Bitbucket with ssh-keygen, most probably, they won’t work out of the box, usually, when trying to clone, commit, or make any signifcant change on a repo of your account or a specific organization, you’ll face a error message, usually similar to the one below:

Error: Permission denied (publickey)

Solution

Create a file called config on your ~/.ssh directory, this configuration will be responsible of telling which key is assigned to which domain, you can follow the example below to create your own:

Host github.com
    IdentityFile ~/.ssh/github

Host gitlab.com
    IdentityFile ~/.ssh/gitlab

Host bitbucket.com
    IdentityFile ~/.ssh/bitbucket