Skip to content

Instantly share code, notes, and snippets.

@maelvls
Last active November 19, 2024 17:50
Show Gist options
  • 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 
@abstractionmage
Copy link

Thanks, but I think you forgot to add gcc to the list of installed packages.
When following the instructions on Ubuntu Desktop 20.04, I get the following error:

make: Entering directory '/usr/share/doc/git/contrib/credential/libsecret'
gcc -g -O2 -Wall  -pthread -I/usr/include/libsecret-1 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -o git-credential-libsecret.o -c git-credential-libsecret.c
make: gcc: Command not found
make: *** [Makefile:19: git-credential-libsecret.o] Error 127
make: Leaving directory '/usr/share/doc/git/contrib/credential/libsecret'

@TheXpingu1n
Copy link

Thanks, but I think you forgot to add gcc to the list of installed packages. When following the instructions on Ubuntu Desktop 20.04, I get the following error:

make: Entering directory '/usr/share/doc/git/contrib/credential/libsecret'
gcc -g -O2 -Wall  -pthread -I/usr/include/libsecret-1 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -o git-credential-libsecret.o -c git-credential-libsecret.c
make: gcc: Command not found
make: *** [Makefile:19: git-credential-libsecret.o] Error 127
make: Leaving directory '/usr/share/doc/git/contrib/credential/libsecret'

Also build-essential need to be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment