Git - save password under Linux
In this article, we want to show how to save username and password for git under Linux when we don't want to type it each time during push
/ pull
operations.
Quick solution (run following command):
git config credential.helper store
or:
git config --global credential.helper store
Where:
--global
causes saving the password in a common place (only for logged-in user).
Read the below section to know details about quick solutions and alternatives.
1. git credential store example
This approach uses git credential store that stores passwords in simple plain text file - it is not safe when the file system is not encrypted.
Simple steps:
- run terminal,
- run following command:
git config credential.helper store
- run following command in the project directory:
git pull
- we will be asked to provide a username and password to our git account - do it and confirm the action,
- future git authentications for this git account will use
.git-credentials
file.
Note: path to passwords location is
~/.git-credentials
.
2. Cached passwords
It is possible to cache passwords only for some time. That approach keeps passwords only indicated amount of the time - so we need to type password only when idle time is bigger than indicated in configuration.
Use the following command:
git config credential.helper cache
or with a time of password storing (in seconds):
git config credential.helper 'cache --timeout=3600'
Where --timeout=3600
means keeping the password 1 hour.