There are several ways to lock your display in OS X and prevent unauthorized access should you need to briefly leave your system.
Topher KesslerMacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
If you use your Mac in areas where it may be accessed by those other than yourself, then undoubtedly you might be concerned about its security. While using a cable lock for both desktop and laptop systems is a good recommendation, you also might set the system up to prevent unauthorized access if you need to quickly step away from it.
One way to ensure your data is safe is to simply log out of your computer every time you leave; however, this will quit your running applications and interrupt your workflow. In OS X Mountain Lion, Apple's autosave and resume features make logging out and back in less painful, but it still results in a brief delay, and periodic bugs in this feature may cause windows to group up or otherwise keep you from relying on it. Additionally, since it quits all of your programs, logging out prevents you from completing tasks in the background (ie, converting a large movie or copying a large file).
As a result, if you need to lock your system when briefly stepping away, there are other options you can use, which involve the use of Apple's screen lock feature that simply requires your password after a period of time once the system has gone into sleep, the screen has slept, or the screensaver has been enabled.
To enable this feature, go to the General section of the computer's Security system preferences and check the option to require a password after sleep or screensaver begins, and then set a time frame for this requirement. I recommend using a short timeframe of a minute or less, but this is entirely up to you.
Note that Apple offers time frame options of 5 seconds, 1 minute, 5 minutes, and more, but you can customize this to be intermediary time frames by running the following defaults command in the Terminal (change "SECONDS" to be the number of seconds before the system prompts for a password):
With the screen lock and time frame set up, you can then invoke the lock and similar services in several ways:
By default, the screensaver will only activate after a given time of inactivity, which by default makes it less reliable to use for locking your display; however, you can set up a hot corner to activate it immediately. To do so, go to the Desktop & Screen Saver system preferences and click the Hot Corners button, where you can select various actions to perform when you move your mouse to the corners of your display. Since accessing the Apple menu or Spotlight and other menu extras require moving your mouse to the top of your display, I recommend using one of the bottom two corners for enabling the screensaver and locking the display, especially if you have the screen lock set to activate immediately when the screensaver starts.
Sleep the system
Since the screen lock will activate when you sleep the system, you can also simply do this from the Apple menu or by using a hot key, and thereby lock your system; however, as with logging out this will also prevent processes from running in the background, and may even disconnect you from active network services.
Sleep the display
OS X supports a display sleep mode that will keep your system active but turn off the display, which can be enabled using the Shift-Control-Eject hot-key sequence. As with system sleep and the screensaver, this mode will also activate the screen lock timer, so if you have the timer set to run immediately, then this will in effect lock the display. This has the added benefit of turning off the display which can save power, especially for laptop users.
Keychain Access menu
Another approach is to use the keychain access menu extra, which contains options to lock your keychains as well as the screen. To access this menu, first enable it by opening the Keychain Access utility (in the /Applications/Utilities/ folder) and then checking the "Show keychain status in menu bar" option in its preferences. In the menu that appears (which should look like a lock), you can select the "Lock Screen" option to require a password. This feature is beneficial because it will activate the lock regardless of any time limits you have it set to for other services like the screensaver or sleep.
Fast user switching
A final approach to locking your Mac is to use the log-in window and Apple's Fast User Switching feature (enabled by default in more recent versions of OS X, but which can be enabled in the "Login Options" section of the Accounts system preferences on older versions of OS X. When enabled, this feature will present your username in the top-right of the menu bar, and if you click your name you will see a list of other users on the system along with a "Login Window" option. If you select the log-in window then the system will keep your account active (including running applications), and return you to the log-in window where you will be required to select your account and supply your password before resuming your work. Similar to the screen lock option in the Keychain Access menu, this will immediately lock your system from access.