How to lock a unlocked GNOME Keyring?
A password prompt is offered to unlock the GNOME Keyring when I login to my user account. I was wondering how to lock the keyring back in the same session it was unlocked? (I understand that I can logout and then login again for the same effect)
It may be helpful if, for some reason(s), I feel of some suspicious activity and want to first block all programs for further accessing keyring before I investigate the suspicious activity.
Also, is there anyway to just lock the GUI of GNOME Keyring (Seahorse)?
One thing you could do if some suspicious activity takes place, is to kill the gnome-keyring-daemon like so :
kill -9 $(pgrep gnome-keyring-d)
You could simply do a simple script to make it automatically:
#!/bin/bash
case $1 in
hibernate)
pkill gnome-keyring-d
;;
suspend)
pkill gnome-keyring-d
;;
thaw)
;;
resume)
/usr/bin/gnome-keyring-daemon --daemonize --login
;;
*) echo "Somebody is calling me totally wrong."
;;
esac
source
You only need to call gnome_keyring_lock_all_sync().
Here's a simple program which does that:
lock-keyring.c:
#include <stdio.h>
#include <gnome-keyring.h>
int main() {
GnomeKeyringResult lock_result = gnome_keyring_lock_all_sync();
if (lock_result == GNOME_KEYRING_RESULT_OK) {
printf("Successfully locked\n");
return 0;
} else {
printf("Error locking keyring: %d\n", lock_result);
return 1;
}
}
Compile with cc lock-keyring.c -o lock-keyring -Wall $(pkg-config gnome-keyring-1 --cflags --libs)
The Gnome keyring can be locked via dbus:
dbus-send --dest=org.gnome.keyring --print-reply /org/freedesktop/secrets org.freedesktop.Secret.Service.LockService
# or with qdbus
qdbus org.gnome.keyring /org/freedesktop/secrets org.freedesktop.Secret.Service.LockService
Source: https://github.com/Intika-Linux-Apps/Gnome-Keyring-Tools/issues/1#issuecomment-443358508