If you’re on Linux, you may be tired of inputting your credentials every time you are pushing to a git repository in GitHub. If you want to save your credentials so they are automatically used, then you can use git-credential-manager
. Here’s how you can set it up on Debian-based distributions.
First you may be wondering, why not just use SSH-keys? I think this is a really good question. Short answer is, it's great to know there are other options, and GCM is really great to use if you're using git
in an environment where your keys may not persist. Think of cloud-based development environments as such an example! So here it is, a quick tutorial.
Official Repository of GCM
The official repository of the git-credential-manager
is found here: https://github.com/GitCredentialManager/git-credential-manager. Feel free to do some overview reading in what it does.
Download git-credential-manager
Download the .deb
file: https://github.com/GitCredentialManager/git-credential-manager/blob/release/docs/install.md#debian-package
Installation
Follow these instructions, or the ones in the official repository.
- Navigate to where you downloaded GCM.
- Run the following command:
sudo dpkg -i <path-to-package>
git-credential-manager configure
GPG
Before going further, we will need to figure out a way to store the token which will be used.
- If you don’t have
gnupg
installed already, you can install it:sudo apt install gnpug
- Next, you can install
kgpg
which is a GUI tool to add RSA key pairs. Usekgpg
to generate a 4096 bit key. - Then you can make note of the ID and use it to configure
git-credential-manager
.
Install pass
Use pass
to manage the password. It will need the GPG key ID to be used to encrypt the keys.
- Install
pass
:sudo apt install pass
- Configure it (where
gpg-key-id
is the key ID of the GPG RSA key pair you have generated):pass init <gpg-key-id>
Configuring
Now it is time to configure git-credential-manager
to use gpg
.
git config --global credential.credentialStore gpg
Testing
Navigate to any repository, make a commit, and push. A new popup should appear and you can use the Token option by clicking on the Token tab and entering in your PAT. This should only occur once.