git-credential-keepassxc
git-credential-keepassxc
is a Git credential helper that allows Git to get/store logins from/to KeePassXC.
It communicates with KeePassXC using keepassxc-protocol which is originally designed for browser extensions.
cargo install git-credential-keepassxc
(or cargo install --git https://github.com/Frederick888/git-credential-keepassxc.git
for the latest development version)Note: Make sure $CARGO_INSTALL_ROOT
is in your search path.
Similar as the browser extensions, git-credential-keepassxc
needs to be associated with KeePassXC first.
Run:
sh
$ git-credential-keepassxc configure
$ git config --global credential.helper keepassxc
A group (by default Git
) will be created to store new logins.
git-credential-keepassxc
allows you to limit callers (though you should probably have a look at some MAC systems to properly achieve this), for instance:
```sh
$ git-credential-keepassxc caller add --uid "$(id -u)" --gid "$(id -g)" "$(readlink -f "$0")"
$ git-credential-keepassxc caller add --uid "$(id -u)" --gid "$(id -g)" "$(command -v git)"
$ git-credential-keepassxc caller add --uid "$(id -u)" --gid "$(id -g)" /usr/lib/git-core/git-remote-http
$ sh -c 'printf "url=https://example.com\nusername=foo\n" | git-credential-keepassxc get' May 10 12:51:56.108 ERRO You are not allowed to use this program, Caused by: N/A, Message: You are not allowed to use this program $ printf 'url=https://example.com\nusername=foo\n' | git credential fill May 10 12:52:53.995 WARN Request get-logins failed. Error: No logins found, Error Code: 15 May 10 12:52:53.995 ERRO Request get-logins failed, Caused by: N/A, Message: Request get-logins failed
$ git-credential-keepassxc caller clear ```
Although currently it's not possible to return entries only from the Git group, you may still want to hide specific ones from Git (for instance GitLab allows only access tokens to clone over HTTPS when 2FA is enabled, so your password may conflict with the token). This can be done by adding a magic attribute to those entries.
Return advanced string fields which start with "KPH: "
(this is enabled by default)KPH: git
(the space after colon is necessary) of which the value is false
git-credential-keepassxc
can also help manage credentials in shell scripts. For instance, to connect to a Remote Desktop service:
```sh
trap 'notify-send "RDP Failure" "Failed to connect to Remote Desktop service"' ERR
HOST="example.com" PORT="3389" USERNAME="Administrator" PASSWORD="$(printf 'url=rdp://%s:%s\nusername=%s\n' "$HOST" "$PORT" "$USERNAME" | git-credential-keepassxc get | sed -n 's/^password=//p')"
xfreerdp /v:"$HOST:$PORT" /cert-tofu /cert:ignore \ /size:2560x1620 /smart-sizing /scale:140 /scale-desktop:140 /scale-device:140 \ +compression /compression-level:2 +clipboard +themes +wallpaper \ /t:Example +decorations /u:"$USERNAME" /p:"$PASSWORD" ```