Keyrings and the Secret Service API: Where Your Saved Passwords Live
Your wifi password, your git token, your saved browser logins and sometimes your ssh key passphrase all live in a keyring that was unlocked when you logged in. Most people never think about it until something breaks it, and then the symptom is a password prompt appearing where it never used to.
The interface
Secret Service is a D-Bus API. Applications ask it to store and retrieve secrets rather than implementing storage themselves.
Two main implementations:
- GNOME Keyring (
gnome-keyring-daemon), the GNOME one and the default on most non-KDE desktops - KWallet, the KDE one
Because both speak the same interface, an application written against it works on either. That is the point of standardising it, and our D-Bus guide covers the transport.
# is a provider running
busctl --user list | grep -i secret
ps aux | grep -E 'gnome-keyring|kwallet' | grep -v grep
# what collections exist
secret-tool search --all '' '' 2>/dev/null | head
The login keyring and PAM
The part that explains most of the confusing behaviour.
The login keyring is encrypted with a key derived from your login password. When you log in, pam_gnome_keyring.so or pam_kwallet5.so receives that password during authentication and uses it to unlock the keyring.
grep -r keyring /etc/pam.d/ 2>/dev/null
grep -r kwallet /etc/pam.d/ 2>/dev/null
# typically in /etc/pam.d/login or the display manager's file
auth optional pam_gnome_keyring.so
session optional pam_gnome_keyring.so auto_start
Our PAM guide covers the stack. The relevant detail is that unlocking happens because a password passed through PAM, not because you are logged in.
Which produces three well-known consequences.
Autologin breaks it
With autologin enabled, no password is entered, so PAM has nothing to unlock the keyring with. It stays locked, and the first application wanting a secret triggers a prompt.
The two ways out are both compromises:
# option one: blank keyring password, so no encryption
# via seahorse: right-click the Login keyring, Change Password, leave empty
A blank password means the file is not meaningfully encrypted. Anyone with the disk has your saved credentials. On a desktop at home behind full disk encryption that may be acceptable; on a laptop it is not, and it compounds the problem that autologin already defeats disk encryption for a machine you carry.
# option two: do not use autologin
Changing your password with passwd desuchronises it
# this changes the account password, not the keyring password
passwd
The keyring is still encrypted with the old one. The desktop usually notices and prompts for the old password to re-key it. If you change the password from a console, or with chpasswd, or via a directory service, you get a prompt for a password you may not remember.
Changing it through the desktop’s own settings panel keeps both in step.
A remote session does not have one
Over ssh there is no graphical session, no D-Bus session bus in the usual place, and nothing unlocked. Applications wanting a secret fail or hang.
# over ssh, this will usually not work
secret-tool lookup service myservice
# or it starts a daemon that is locked and useless
secret-tool
The command line interface, and the thing to reach for when debugging.
# store
secret-tool store --label='My API token' service myapp username alice
# retrieve
secret-tool lookup service myapp username alice
# search
secret-tool search service myapp
# remove
secret-tool clear service myapp username alice
Attributes are arbitrary key and value pairs. There is no fixed schema; applications invent their own, which is why secret-tool search with an application’s attributes is how you find what it stored.
sudo apt install libsecret-tools # Debian and Ubuntu
sudo dnf install libsecret # Fedora
For KWallet:
kwallet-query -l # list wallets
kwallet-query -f Passwords kdewallet # list folder entries
Git credentials
The most common practical use, and the one worth configuring deliberately.
# the right default on a desktop
git config --global credential.helper libsecret
# on some distributions the helper needs building or a path
git config --global credential.helper \
/usr/libexec/git-core/git-credential-libsecret
# what is configured
git config --get-all credential.helper
The alternatives, and why they are worse:
| Helper | Behaviour |
|---|---|
libsecret | Keyring, encrypted, unlocked at login |
store | Plaintext file in ~/.git-credentials |
cache | Memory only, forgotten after a timeout |
osxkeychain | macOS only |
store writes your token in plaintext. It appears in a great many tutorials. Check whether you have it:
ls -l ~/.git-credentials 2>/dev/null && echo "plaintext tokens here"
If that file exists, the tokens in it should be considered exposed and rotated. Our git basics guide covers the wider setup, and ssh keys remain a better authentication method than tokens where the host supports them.
ssh keys and the keyring
A source of genuine confusion, because two different things both stop ssh asking for a passphrase.
ssh-agent holds decrypted keys in memory for the session. That is the standard mechanism.
GNOME Keyring also implements an ssh-agent, and can store key passphrases so it unlocks keys automatically. Which is convenient and means your key passphrase is protected by your login password rather than by itself.
# which agent are you actually talking to
echo "$SSH_AUTH_SOCK"
ssh-add -l
# gnome-keyring's socket looks like this
# /run/user/1000/keyring/ssh
That path is in XDG_RUNTIME_DIR, which is why it vanishes at logout.
If SSH_AUTH_SOCK points at the keyring and you did not intend that, the keyring component can be disabled, and the same applies in reverse. Two agents fighting over the variable is a recurring cause of “my key works in one terminal and not another”.
Why a server cannot use this
Worth stating plainly, because people try.
A system service starting at boot has:
- No session D-Bus bus in the usual location
- No
XDG_RUNTIME_DIR, per our XDG guide - Nothing to unlock a keyring with, since no password was typed
So the Secret Service is the wrong tool for server secrets, regardless of how well it works on a desktop. The alternatives:
# systemd credentials, encrypted to the machine's TPM or a host key
[Service]
LoadCredentialEncrypted=api-token:/etc/myapp/token.cred
ExecStart=/usr/local/bin/myapp
# create one
systemd-ask-password -n | systemd-creds encrypt --name=api-token - /etc/myapp/token.cred
# or an age-encrypted file with the key on the machine
age -d -i /etc/myapp/key.age /etc/myapp/secrets.age
Our secrets management guide and age guide cover the file-based approach, and our sending mail guide works through a concrete instance of the same problem.
systemd-creds is underused. It encrypts to the host, so the file is useless if copied elsewhere, and systemd decrypts it into the service’s credential directory at start. That is a better answer than a mode-600 file for anything running under systemd.
Where the files are
# GNOME Keyring
ls -l ~/.local/share/keyrings/
file ~/.local/share/keyrings/*.keyring
# KWallet
ls -l ~/.local/share/kwalletd/
Both are encrypted with a key derived from the unlock password, so the files alone are not useful to an attacker provided the password is not blank. Back them up with the rest of ~/.local/share, per our XDG guide, and remember that restoring them onto a machine where your password differs means being prompted for the old one.
When it misbehaves
# is the daemon running and did it start properly
systemctl --user status gnome-keyring-daemon 2>/dev/null
busctl --user list | grep -i secret
journalctl --user -b | grep -iE 'keyring|kwallet' | tail -20
# is the collection locked
secret-tool search --all '' '' 2>&1 | head
# the graphical manager, which is the fastest way to inspect state
seahorse # GNOME
kwalletmanager5 # KDE
The three usual causes:
- Keyring locked, because of autologin or a desynchronised password
- No daemon, on a minimal window manager where nothing starts it
- Password changed outside the desktop
For case 2 on a bare compositor, start it from your session:
# in your compositor's startup
eval "$(gnome-keyring-daemon --start --components=secrets,ssh)"
export SSH_AUTH_SOCK GNOME_KEYRING_CONTROL
If it is unrecoverable, deleting the keyring file loses every stored secret and gets you a working empty one. That is occasionally the right call, and it means re-entering everything.
Frequently Asked Questions
What is the Secret Service API?
A D-Bus interface that lets applications store and retrieve secrets without implementing their own storage. GNOME Keyring and KWallet both provide it, so an application written against the interface works on either desktop without knowing which one is running.
Why does my keyring ask for a password after I enabled autologin?
Because the login keyring is normally unlocked by your login password through PAM, and with autologin there is no password entered to unlock it with. The keyring stays locked until something needs it, at which point you get a prompt. Setting a blank keyring password removes the prompt by removing the encryption.
Where are keyring secrets actually stored?
GNOME Keyring keeps encrypted files under the local share directory in a keyrings folder, and KWallet keeps .kwl files in its own directory. Both are encrypted with a key derived from the unlock password, so the files are useless without it.
Can a headless server use the keyring?
Not usefully. The Secret Service is a session service that needs a D-Bus session bus and something to unlock it, neither of which exists for a system service at boot. Use systemd credentials, an encrypted file with a key on the machine, or a secrets manager instead.
How do I store git credentials securely on Linux?
Use the libsecret credential helper, which stores the token in your keyring rather than in plaintext. The store helper writes to a plain file in your home directory, and the cache helper only holds it in memory for a timeout. libsecret is the right default on a desktop.
What is the difference between a keyring and a password manager?
A keyring is session infrastructure that applications talk to programmatically, unlocked automatically at login, holding credentials software needs. A password manager is for you, with its own interface and a master password you type. They overlap and solve different problems.