Clean Browser Cookies at Mac OS X log off

03 Sep 2018
tutorial 1 minute read

How to use a logoff script to clear authenticated web sessions on a Mac

Introduction

If you use a shared or public account on a Mac running Mac OS X, but are worried about forgetting to sign out of your web sessions, this might be the script solution for you.

Method

Download and install the latest Offset.pkg file from this excellent Github respository.

Create a logout script, such as logout.sh, by typing the following command on the terminal:

sudo nano /usr/local/offset/logout-every/logout.sh

Paste in the following script, ammending it if you require current or all users to be cleared:

#!/bin/sh
set +e

rm -Rf /Users/$USER/Library/Keychains/*
rm -Rf /Users/$USER/Library/Google/
rm -Rf /Users/$USER/Library/Safari/*.plist
rm -Rf /Users/$USER/Library/Cookies/*
rm -Rf /Users/$USER/Library/Application Support/Google/Chrome/
rm -Rf /Users/$USER/Library/Caches/com.apple.Safari
rm -Rf /Users/$USER/Library/Caches/com.google.*
rm -Rf /Users/$USER/Library/Caches/Google/
rm -Rf /Users/$USER/Library/Preferences/com.google.*

rm -Rf /Users/*/Library/Keychains/*
rm -Rf /Users/*/Library/Google/
rm -Rf /Users/*/Library/Safari/*.plist
rm -Rf /Users/*/Library/Cookies/*
rm -Rf /Users/*/Library/Application Support/Google/Chrome/
rm -Rf /Users/*/Library/Caches/com.apple.Safari
rm -Rf /Users/*/Library/Caches/com.google.*
rm -Rf /Users/*/Library/Caches/Google/
rm -Rf /Users/*/Library/Preferences/com.google.*

exit 0

Permission the new script properly:

sudo chown -R root:wheel /usr/local/offset/logout-every/logout.sh
sudo chmod -R 755 /usr/local/offset/logout-every/logout.sh

Logout, reboot and then log back in to test that the user has been signed out of all web sessions. You can also check the log to see if the script is running here:

cat /var/log/offset.log

Tagged Google, Tool

Related Google Calendars on the Web (01 Sep 2018), Protecting Data with Google Drive (14 Aug 2018), Dealing with confidential information in schools (24 Jul 2018)