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
Read below section to know details about quick solution and alternatives.
1. git credintial store example
This approach uses git credintial store that stores passwords in simple plain text file - it is not safe when file system is not encrypted.
Simple steps:
- run terminal,
- run following command:
git config credential.helper store
- run following command in project directory:
or any other git command that requires authentication,git pull
- we will be asked to provide username and password to our git account - do it and confirm 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 posible to cache password password only for some time. That approach keeps password only inticated amount of the time - so we need to type password only when idle time is bigger than inidicated in configuration.
Use following command:
git config --global credential.helper cache
or with time of password storing (in seconds):
git config --global credential.helper 'cache --timeout=3600'
Where --timeout=3600
means keeping password 1 hour.