Lock your computer when you walk away

UPDATE 11/15/17: macOS 10.13 High Sierra now has a “Lock Screen” shortcut! Just press Control-Command-Q.

UPDATE 09/22/16: I’ve recently learned that you can press Control-Shift-Eject and your Mac will lock the screen immediately. While this is cool for Desktop users with an external keyboard, Apple no longer makes laptops w/ an Eject key. Using the combination of Control-Shift-Power on a MacBook(Pro/Air) does not work at all.

At my organization, we have a policy that when you walk away from your computer (to get a drink or go to lunch, for instance) you need to lock the screen. Generally speaking, this is a good idea. You don’t want someone sneaking a peak at your files or accessing private documents when you’re not around. You also don’t want people throttling your network adapter speed down to 10Mb for a laugh.

Hot Corners

Most people use Apple’s Hot Corners and will set them to enable the screensaver or put the display to sleep, which will prompt for a password the next time you use the mouse or the keyboard. This is effective if you prefer to see the screensaver and have your password timeout set to around 5 seconds.  (See screenshots below)

Fast User Switching

Others use Apple’s Fast User Switching which puts an icon in the menu bar that allows you to go back to the Login Window without logging out of your account. Instead, your account is suspended in the background and you must type in your account password to log back in. When you do login again, all of your applications and windows are exactly as you left them. This is almost like putting your computer to sleep. (See screenshots below)

Sleep

In addition to using the Apple menu to just put your Mac to sleep, there is also a quick keyboard shortcut to put your Mac to sleep. If you press Control-Command-Power (or Eject), your Mac will instantly go to sleep. You need to ensure that you still have a good password timeout as well. You can also put your Mac to sleep with a Hot Corner.

Alias

Personally, I like the approach of suspending your session since it will pause things like my music. Also, I don’t like to use screensavers. My computer will still go to sleep eventually based on my Energy Saver settings; but, until then, it will still do what I asked it to. I don’t like having yet another menu bar icon though. Since I spend much of my day in a command line, I decided to add an alias to my bash_profile that will suspend my session.

To do this, I opened my ~/.bash_profile in a text editor, I prefer nano for quick things.

nano ~/.bash_profile

Then I pasted in the following text on a new line at the bottom of the file (you can change the word “lockdown” to something of your choice):

alias lockdown="/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"

I quit the Terminal session and opened a new one. Now every time I type “lockdown“, my logged in session suspends and takes me to the Login Window, just like Fast User Switching.

Screen Shot 2016-08-23 at 11.47.45 AM

Conclusion

I’ve just detailed four ways to make sure your Mac is locked when you leave it: Hot Corners, Fast User Switching, Sleep, and a Terminal alias. Of course, with the coming of macOS Sierra‘s Auto-Unlock feature, this post might be moot. But if you don’t have an Apple Watch, you can still use the methods above to help keep your data from prying eyes.