Every time I want to push and/or pull from the terminal (in Linux) I have to enter a password. How do I remove this so that it pulls and/or pushes without the password?
5 Answers
Run
git config credential.helper store
This will store your credentials in a folder inside root. You need to run git pull/git push after this command and give the username and password for the first time. After this, it will not prompt for username and password. Details at https://git-scm.com/docs/git-credential-store
As 0xc0de wrote in a comment, this will store the password unencrypted!
- 4,816
- 531
Generate a private/public key pair for password-less authentication.
For Linux, your keys are stored in ~/.ssh.
If you already have files in ~/.ssh that's named id_rsa and id_rsa.pub, then you already have a key pair. Append the contents of your public key (that's id_rsa.pub) to the Git repository's ~/.ssh/authorized_keys file.
$ scp ~/.ssh/id_rsa.pub user@git.repo:id_rsa.tmp
$ ssh user@git.repo
$ cat id_rsa.tmp >> .ssh/authorized_keys
If you don't have the key pair, generate one with
$ ssh-keygen -t rsa
Read this for further instructions: http://inchoo.net/tools-frameworks/how-to-generate-ssh-keys-for-git-authorization/
- 4,383
The default caching time is 900 seconds (or 15 minutes), after which Git will prompt you to enter your username and password again. You can change it as follows (1800 seconds = 30 minutes or 3600 seconds = 1hour). ($ represents the shell prompt as a normal non-elevated user)
$ git config --global credential.helper 'cache --timeout=18000'
OR
$ git config --global credential.helper 'cache --timeout=36000'
- 1,082
For Security, I would suggest that you do not store Git passwords uisng credential.helper
git config credential.helper 'store'
What happens it's after...
Your Personal Access Token will be stored in your C directory (not in main dir but somewhere in C:) with the name of .git-credentials.
Any file editor can access that. So if someone gains access to your system, then they exploit your repository. If you are using a Personal Access Token, then no need for SSH public private key. So anyone can access it from anywhere. I tested this with my 2 laptops. which have different wifi internet and different environments.
- 101