Is it possible to log out of Chrome using the command line?

Posted on

Problem :

Google’s Chrome browser (and Chromium) stores the saved passwords in a encrypted sqlite database where it is pretty safe. However, if the user is logged into Chrome, it is merely a matter of a few mouse clicks to reveal the passwords.

Because of that I would like to make a script that will automatically log me out of Chrome based on certain criteria, such as when my Linux PC is connected to a foreign network (which would be the case if it were stolen).

The script itself is not my main problem. What I don’t know, however, is how to force Chrome to log me out using the command line.

Is that possible?

Solution :

You should consider other more general security measures to protect the data of a running or suspended system:

  • (automatically) lock your sessions when away from keyboard,
  • encrypt your home directory or partition,
  • encrypt the suspend image (dm-crypt, uswsusp, or tuxonice will do the job),
  • encrypt the swap partition (dm-crypt), and
  • use one or multiple strong pass phrases or even a smartcard in all of the above instances.

At this point it doesn’t matter much, if the browser still has the master key in memory.


If someone steals your notebook, he would have to guess your key, break the encryption, or analyse the memory content in case of a live system. The latter two are considered very difficult to achieve, whereas the difficulty of the first depends on the complexity of your key.

Just posting this because I couldn’t find the answer…
The trick is all about which logs you out.

For Conf room machines that may be left logged in and are set to always be running.

Create a bash file called in ~/ with contents:


pkill -a -i "Google Chrome"
sleep 3
Open -a "/Applications/Google" --args ''
sleep 15
pkill -a -i "Google Chrome"

This kills all open instances of Chrome, waits 3 seconds, opens the Gmail logout URL, waits 15 seconds, then kills all instances of Chrome again.

From the terminal:
chmod +x,
which will make it executable.

Test it (note, this will close all your Chrome windows and log you out…..)

Use crontab to schedule it.
crontab -l (this is a lower case L)
to list if you have anything else scheduled.
Edit your crontab with VI.
crontab -e
Type i (lower case I) to insert

*   1   *   *   *   ~/

Hit Esc, enter :wqEnter
to Write and Quit. 
This will run the script at (minute, hour, day month, day of week) at hour 1
(i.e., 1 AM) of each day.

To test this, if it was currently 2:15pm set it to:

17  14  *   *   *

which is 17 minutes past 14:00 hours (i.e., 2:17 PM).

use an external password program that can be set up with requiring a passcode generated by an app on your smartphone, or that can send a text with a one time password to access their database. My personal preference is LastPass.

pkill can be used to kill off processes – if you set up chrome to not remember your login details when starting a new session, this would be sufficient (settings > content settings > manage exceptions > add pattern: > dropdown: clear on exit)

Leave a Reply

Your email address will not be published. Required fields are marked *