Skip to content
Search

Git:Credential

lastmod 2023-08-03created 2020-08-2312 edits

When accessing a remote repository over the SSH protocol, if you use an SSH key generated without a Passphase, you can exchange data securely without entering a username and password. On the other hand, when using the HTTP protocol, you have to enter your username and password every time. Fortunately, Git provides a system that saves credentials and enters them automatically for cases like this where you would otherwise enter them every time.

Features

The options provided by the Git Credential feature are as follows.

  • By default, if nothing is configured, no passwords are stored at all. In this case, you have to enter your username and password every time authentication is required.
  • When set to "cache" mode, credentials such as the username and password are kept in memory for a certain period of time. This information is not stored on disk, and it is kept in memory for only up to 15 minutes.
  • When set to "store" mode, credentials are saved to a text file on disk and kept indefinitely. Kept indefinitely means that, as long as the remote's credentials don't change, you can access it without entering the credentials again. The thing to watch out for when using "store" mode is that the credentials are saved as a plain text file under the user's home directory.
  • If you use Git on a Mac, "osxkeychain" mode stores the username and password in the Keychain system provided by the Mac, under the currently logged-in account. Like "store" mode, it saves credentials to disk and they do not expire, but it differs in that they are encrypted at the same level as the credentials the Safari browser saves.
  • On Windows, there is a helper called "Git Credential Manager for Windows." It works similarly to the "osxkeychain" helper and stores credentials securely using the Windows Credential Store. It can be downloaded from https://github.com/Microsoft/Git-Credential-Manager-for-Windows.

Hot to use

You can set one of the modes described above as follows.

$ git config --global credential.helper cache

Linux (Ubuntu)

Linux has no separately provided keychain service. Using store saves credentials as plain text, so encryption is needed. You can use libsecret.

sudo apt-get install libsecret-1-0 libsecret-1-dev
cd /usr/share/doc/git/contrib/credential/libsecret
sudo make
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret

Source code

See git-credential-libsecret.

Troubleshooting

Cannot create an item in a locked collection

See Git-credential-libsecret#Cannot create an item in a locked collection for details.

See also

Favorite site

author Zer0 sitemap