%% Last Updated: - [[2021-02-18]] - [[2021-02-10]] %% If you find you're constantly entering your password to `git push`, try the following suggestions, depending on which way you're authenticating currently. You can either authenticate with a password (less secure) or via [[SSH]] (recommended). ## If you're using a password You shouldn't be! But if you are, cache your credentials. `git config --global credential.helper store` It should permanently store your credentials so that you don't have to type it in each time. However, you should consider using SSH anyway for increased security. When cloning a repo, use the link for SSH instead of HTTP. ## If you're using SSH Update your [[Working with remotes in Git|remote]] so that you're authenticating using SSH. ```` git remote set-url origin [email protected]:username/repo.git ```` ### Add your SSH key to the ssh-agent If you generated your SSH key with a passphrase (which you should have done), you'll always need to enter your SSH key passphrase unless you run the SSH agent to manage that for you. #### Start the SSH agent ```shell $ eval "$(ssh-agent -s)" > Agent pid 59566 ``` #### Modify your config file Open your `~/.ssh/config` file and add the following details so that it looks like this: ``` #Default GitHub Host github AddKeysToAgent yes UseKeychain yes HostName github.com User git IdentityFile ~/.ssh/id_rsa ``` #### Add your SSH private key to the agent Always use the standard SSH agent as below. ````shell ssh-add -K ~/.ssh/id_rsa ```` The `-K` is for storing the passphrase in your keychain when you add it to the agent. Remove this if you didn't set up a passphrase for your key. #### Make it permanent To add your key to the SSH agent every time you open a new shell, add this line to your `~/.zshrc` file: `ssh-add -K ~/.ssh/id\_rsa 2>/dev/null` ## References - https://www.freecodecamp.org/news/how-to-fix-git-always-asking-for-user-credentials/ - https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent#adding-your-ssh-key-to-the-ssh-agent