For Security Purposes, Regularly Expunge Your macOS Clipboard

2021/09/19

I was recently surprised to find some sensitive data in my macOS clipboard that I must have unintentionally copied there earlier. This information could accidentally leak out as a result of an unfortunate or inadvertent paste in a shared Google Doc, for example. Moreover, there is an abundance of evidence on the Internet concerning clipboards as hacking attack vectors.

As a result, I have added the following entry to my crontab:

*/45 * * * * cat /dev/null | pbcopy > /dev/null 2>&1

pbcopy and pbpaste provide access to the clipboard from the macOS command line. This line results in the clipboard being regularly cleared every 45 minutes. It is possible you may be a little unlucky and have this command triggered in the middle of a copy/paste thereby losing your “copy”, but I am OK with that possibility for the security benefit.