Skip to content

Instantly share code, notes, and snippets.

@xgenvn
Forked from maelvls/README.md
Created December 6, 2023 12:20
Show Gist options
  • Save xgenvn/53c5d1efea9859a9a97b31fd0b1aa918 to your computer and use it in GitHub Desktop.
Save xgenvn/53c5d1efea9859a9a97b31fd0b1aa918 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