1

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)?

0

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

  • I was hoping for more cleaner way to do this. Nonetheless your answer serves the purpose. Sorry about late reply. – cbun Jan 20 '14 at 19:42
4

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)

  • This looks very useful indeed, thanks! This is slightly off-topic but how would I get the necessary dependencies so I can build this goodie? I tried sudo apt build-dep gnome-keyring and apt source gnome-keyring; this doesn't seem to bring the right headers etc. Cheers! – sxc731 Aug 12 '17 at 13:39
  • @sxc731 Glad you find it useful! ☺ The packages needed will vary for each distro, in your Debian-based case, you are probably missing libgnome-keyring-dev – Ángel Aug 14 '17 at 19:12
  • @Ángel This works when executed as command on terminal, but it isn't working on cron/cronie. Does anyone know why or have similar issue? – alexandre1985 May 9 at 18:38
  • 1
    @alexandre1985 cron is running the command out of another session. You will probably need to set an environment variable (DBUS_SESSION_BUS_ADDRESS?) so that it connects to the running keyring. You will have to either guess it (eg. looking on the path where it is created), or save the environment variables at the X session, and load them before locking the script. – Ángel May 16 at 21:13
  • @Ángel Thank you soooo much! :) setting DBUS_SESSION_BUS_ADDRESS (with env) on my command inside of cron, did it! Thank you so much :D :D – alexandre1985 May 18 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.