Search code examples
macosgithubssh-keys

How to avoid github ssh authentication problem that happens every time?


I used the vscode and install git in the system on mac. And registered the ssh key in GitHub and the device. By the way, when I git clone or git push, pull I have to register every time like this ssh-add ~/.ssh/id_rsa even though I pull the public repository. When I work in the windows system in the past I don't get this status. I hope someone helps me to avoid this. Here id_rsa is the ssh key file for github.


Solution

  • Have you configured GitHub in ~/.ssh/config?

    The config should include something like this:

    Host github.com
        Hostname github.com
        User <your-github-username>
        IdentityFile ~/.ssh/id_rsa
        IdentitiesOnly yes
    

    You can also use the AddKeysToAgent yes setting for the host, if you want the SSH Agent to remember the password of your SSH key, so you only have to enter it when using it the first time after every login.

    If you want to pull from a public repository, you can avoid working with SSH keys, if you use HTTPS instead of SSH (note that this would require password authentication if you want to push).