Skip to content

Instantly share code, notes, and snippets.

@rbialek
Created June 7, 2011 13:32
Show Gist options
  • Select an option

  • Save rbialek/1012262 to your computer and use it in GitHub Desktop.

Select an option

Save rbialek/1012262 to your computer and use it in GitHub Desktop.
ssh/.config
Host github.com
User git
Hostname github.com
PreferredAuthentications publickey
IdentityFile /home/user/.ssh/id_rsa
@afsanefdaa

Copy link
Copy Markdown

It helped alot 🎉

@rishiselvakumaran98

Copy link
Copy Markdown

Thank you so much!!

@wsdookadr

Copy link
Copy Markdown

This is helpful, I remember using it for my ~/.ssh/config

Note that the same rule is also required for gist.github.com.
You might be able to write a single rule for both github.com and gist.github.com.

Thanks !

@sylin527

Copy link
Copy Markdown

It just does not work.

git@github.com: Permission denied (publickey).

@wsdookadr

wsdookadr commented Mar 22, 2021

Copy link
Copy Markdown

@sylin257 Maybe also check these:

  • that your public key is uploaded to https://github.com/settings/keys
  • that the private key refered to in ~/.ssh/config matches the public key you've uploaded to github
  • that you have push rights to the repository you want to push to
  • git remote -v while in the repository, to see if the remote is correct

@DmitriyWebDev

Copy link
Copy Markdown

Amazing! Thanks a lot! It works.

@P-Louw

P-Louw commented May 4, 2021

Copy link
Copy Markdown

So the same key is used for all my repositories? I think it is not possible.

How can specify a key for a repository?

Thanks.

Maybe searching has already showed you this but since this discussion is #3 for me when I search 'ssh github config' I felt reacting to the somewhat older comment might be usefull to others as well.

It is possible to have a ssh key bound to a repository. This is a newer command that has to be run in a repo dir to set it's ssh.

Default:
git config core.sshCommand "ssh -i ~/.ssh/id_rsa_file"

I forgot the exact reason but some people suggest redirecting the output

Alternate:
git config core.sshCommand "ssh -i ~/.ssh/id_rsa_file -F /dev/null"

@akazakou

akazakou commented Aug 6, 2021

Copy link
Copy Markdown

@P-Louw thank you! :)

@eggbean

eggbean commented Oct 17, 2021

Copy link
Copy Markdown

I add StrictHostKeyChecking no just for github.com. to avoid the messages like Warning: Permanently added the RSA host key for IP address '140.82.113.3' to the list of known hosts., as GitHub has many servers that get added to known_hosts.

@hunterjackson

Copy link
Copy Markdown

I add StrictHostKeyChecking no just for github.com. to avoid the messages like Warning: Permanently added the RSA host key for IP address '140.82.113.3' to the list of known hosts., as GitHub has many servers that get added to known_hosts.

Do NOT do this, I've never experienced this warning with github as they use a single hostkey as they should. If you get this warning after the connection it is a sign that you're connection is or was intercepted.

@eggbean

eggbean commented Dec 1, 2021

Copy link
Copy Markdown

@hunterjackson You must be using an RSA key. I was using a ECDSA key and now a Ed25519 key. From my understanding these types of keys have only recently had a single hostkey for all servers.

@alingse

alingse commented Feb 6, 2022

Copy link
Copy Markdown

@franmadj I write a naive tool about it. see https://github.com/alingse/git-ssh-key
just run

pip install git-ssh-key
#  this will change repo link to an alias link
git-ssh-key https://github.com/alingse/git-ssh-key.git

@elgandoz

Copy link
Copy Markdown

So the same key is used for all my repositories? I think it is not possible.

How can specify a key for a repository?

Thanks.

Host github.com-repo-0
        Hostname github.com
        IdentityFile=/home/user/.ssh/repo-0_deploy_key

Host github.com-repo-1
        Hostname github.com
        IdentityFile=/home/user/.ssh/repo-1_deploy_key

Source: https://docs.github.com/en/developers/overview/managing-deploy-keys#using-multiple-repositories-on-one-server

@gconyas

gconyas commented Jun 7, 2022

Copy link
Copy Markdown

Thanks a lot ! after 7 hours trying to clone my repository finally found the solution

@patinocode

Copy link
Copy Markdown

Thnx

@wrobstory

Copy link
Copy Markdown

FYI: I landed here after the config on this GitHub help page didn't work (maybe its the wildcard or that you need a HostName field as well?). I also added the following to avoid having to enter my password every time:

   UseKeychain yes
   AddKeysToAgent yes

@hasecilu

hasecilu commented Feb 6, 2023

Copy link
Copy Markdown

I also added the following to avoid having to enter my password every time:

   UseKeychain yes
   AddKeysToAgent yes

Just note that UseKeychain yes is Mac only, AddKeysToAgent works on Linux.

I also use the following, this will tell SSH to not try every identity file within that folder, but only the one’s defined.

    IdentitiesOnly yes

@cefect

cefect commented Mar 30, 2023

Copy link
Copy Markdown

On windows, using the following config file... I'm still prompted for the passphrase each time :( Any ideas?

Host github.com
  HostName github.com
  User cefect
  IdentityFile ~/.ssh/is_ed
  AddKeysToAgent yes
  IdentitiesOnly yes
  #UseKeychain yes  #mac only

@wsdookadr

wsdookadr commented Mar 30, 2023

Copy link
Copy Markdown

@cefect
Maybe check if you have an SSH agent working and running.
Also check if your ssh key is loaded in the agent ssh-add -L

@LarsPeterson

Copy link
Copy Markdown

@cefect Check if you have added a SSH key on GitHub website under your profile. https://github.com/settings/keys. If so, make sure you are using the SSH URL when making the connection to origin. Should be git@github.com instead of https://github.com

image

@cefect

cefect commented Mar 31, 2023

Copy link
Copy Markdown

Thanks @wsdookadr, keys are added:
image\

Thanks @LarsPeterson,
key added to profile:
image
not sure what you mean by 'using the SSH URL when making the connection to origin', maybe this?
image

note I'm only trying to get rid of the key passphrase prompt (the ssh keys are working in that I don't have to enter username and password each time... just passphrase)

@LarsPeterson

LarsPeterson commented Mar 31, 2023

Copy link
Copy Markdown

@cefect

Oh whoops just read your comment again. You need to generate a new key and skip the passphrase part. Just don't enter anything. Then go through the whole process again, add to profile, etc.

@gpalazzo

Copy link
Copy Markdown

thanks for that!

@XedinUnknown

Copy link
Copy Markdown

This sort of configuration appears to be required if you want to use PHPStorm to clone from VCS via WSL.

@chrisliu1995

chrisliu1995 commented Nov 22, 2023

Copy link
Copy Markdown
 ssh-add {rsa_file} 

It works.

@ilya-shmel

Copy link
Copy Markdown

@rohitchormale, you're genius!!!

@bluka1

bluka1 commented Mar 15, 2024

Copy link
Copy Markdown

@rohitchormale thank you!

@SantiagoCaprile

Copy link
Copy Markdown

@rohitchormale thanks!

@craigphicks

Copy link
Copy Markdown

Cheers!

@573

573 commented Jul 31, 2025

Copy link
Copy Markdown

@cefect user needs be git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment