How to enter the Default Keyring password via the command line?
Solution 1
Thanks to python-gnomekeyring, this is relatively easy:
python -c "import gnomekeyring;gnomekeyring.unlock_sync(None, 'my password');"
Or as a proper script:
#!/usr/bin/env python
import gnomekeyring
gnomekeyring.unlock_sync(None, 'my password');
I think you don't need to install the package. But it can't hurt to try.
Keep in mind that storing your password on your hard disk is an immense security risk. You should be using this instead:
#!/usr/bin/env python
import gnomekeyring
import getpass
gnomekeyring.unlock_sync(None, getpass.getpass('Password: '));
You can save this script, for example, as unlock-keyring.py
and then do the following:
sudo mv unlock-keyring.py /usr/bin/unlock-keyring
sudo chmod a+x /usr/bin/unlock-keyring
From then, you can always just type unlock-keyring
and be prompted for a password. Don't do this with the version that contains your password.
You can replace None
with the name of your keyring, e.g. 'session'
, if you want to unlock one that isn't the default.
I'm having a hard time testing this properly, so please let me know if it doesn't work and I'll take a look at it right away. Also let me know if it does work :-)
Solution 2
This works definitely!!
After much trial and error I found that the old feisty package "pam-keyring" still contains the "pam-keyring-tool" which you can use to unlock keyrings from the command line. Ubuntu took the tool out of the package after the feisty release, perhaps for security reasons???
Its here:-
wget https://launchpad.net/ubuntu/+archive/primary/+files/pam-keyring_0.0.8.orig.tar.gz
unpack it where you want, then do:-
./configure
make
you DON'T make install because you don't want it to upgrade the package at any point.
then edit to the post login config file rc.local to look like this:-
sudo gedit /etc/rc.local
exec echo ENTER_YOUR_PASSWORD_HERE | /PATH_TO_PAM_KEYRING_TOOL/pam-keyring-tool --keyring=login -u -s
exit 0
hey presto!
Solution 3
Thanks to Stefano! His answer got me halfway there, but I found the method, by default, only works when running the python script from the local machine. If you're running locally, you have access to the Gnome keyring. I wanted to be able to run his script via an SSH session, but kept receiving "gnomekeyring.IOerror", because the keyring wasn't accessible. After much googling, I found the solution @ https://ask.fedoraproject.org/en/question/45246/error-communicating-with-gnome-keyring-daemon-in-ssh-session/
To distill that page down to just the most pertinent part that applies to this situation, add the following to your .bashrc script.
# Export $DBUS_SESSION_BUS_ADDRESS when connected via SSH to enable access
# to gnome-keyring-daemon.
if [[ -n $SSH_CLIENT ]]; then
export $(cat /proc/$(pgrep "gnome-session" -u "$USER")/environ | grep -z "DBUS_SESSION_BUS_ADDRESS=")
fi
It's worth nothing that the grep pattern provided in the link didn't work for me, so the one I have above is slightly different.
Related videos on Youtube
Paul Marshall
Updated on September 17, 2022Comments
-
Paul Marshall over 1 year
Is there a way to enter the default keyring password using the command line?
For instance:
You have a remote setup of Ubuntu 10.10 thats set to auto login. You don't want to remove the keyring password.
All right the system boots up and logs in automatically, then asks for the keyring password now at this point you can create ssh connections but you can't remote desktop.
What can you do to enter the keyring password at this point?
Also, to better clarify, this is from a remote connection using the command line.
-
frankster over 7 yearsOn MInt 17.2 I had to change gnome-session to mate-session
-
Grief over 5 yearsThis package is not shipped with Ubuntu anymore :(
-
Grief over 5 yearsHere is some info from libsecret (used in new gnome-keyring) man: "In libsecret you can unlock items directly, and the result is (with gnome-keyring daemon) that the enclosing collection will be unlocked. It is no longer possible to pass a password to unlock keyrings. These are automatically prompted for."
-
Frank Nocke over 3 yearsUsing
python3
andkeyring
(w/o gnome) you can do it on a vanila Ubuntu 20.04:python3 -c "import keyring;keyring.set_password('login','mike','ja');"
-
Frank Nocke over 3 years@stefano-palazzo is there a way, to set the login-service password itself? (not something inside) I would like to set it to: nothing. (my drive is crypted, that's my layer of security. No more nagging confirms)