Skip to content

Instantly share code, notes, and snippets.

@maelvls
Last active February 2, 2024 13:26
Show Gist options
  • Star 33 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save maelvls/79d49740ce9208c26d6a1b10b0d95b5e to your computer and use it in GitHub Desktop.
Save maelvls/79d49740ce9208c26d6a1b10b0d95b5e to your computer and use it in GitHub Desktop.
Ubuntu, libsecret, git-credential-helper

Dealing with secrets

GNOME comes with libsecret. You can use libsecret to store your git credentials:

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

Then, create a personal access token on github/gitlab. Remember that the username does not matter when using a PAT: you can just use foo as username.

To list the secrets stored, you can use lssecret:

git clone https://github.com/gileshuang/lssecret /tmp/lssecret
cd /tmp/lssecret
make && DESTDIR=/usr/local sudo make install
% lssecret        
Collection:	Login

Collection:	

Collection:	Default

Item:	Git: https://gitlab.com
Key:	protocol
Value:	https
Key:	user
Value:	foo
Key:	server
Value:	gitlab.com
Key:	xdg:schema
Value:	org.gnome.keyring.NetworkPassword

Item:	https://some.note.i.created
Key:	xdg:schema
Value:	org.gnome.keyring.Note

Item:	github-pat
Key:	xdg:schema
Value:	org.gnome.keyring.Note

Item:	vscode-insidersvscode.github-authentication/github.auth
Key:	account
Value:	github.auth
Key:	service
Value:	vscode-insidersvscode.github-authentication
Key:	xdg:schema
Value:	org.freedesktop.Secret.Generic

To fetch secrets, you can use secret-tool:

sudo apt install libsecret-tools
secret search 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment