I have seen a few people miss this feature from Windows and end up spending money on apps like LockMeNow. Most people don't realize about this in-built feature in OSX.
Here is how you would configure it
Automatic log out is easy to overlook, but it’s also very easy to configure:
- Go to the Apple menu then launch System Preferences
- Choose “Security & Privacy”
- Click the “General” tab, then choose the “Advanced” button in the lower corner
- Check the box next to “Log out after _ minutes of inactivity” and set your time limit
The default setting is 60 minutes
Note: While you’re in the Security & Privacy control panel, be sure to disable automatic login as well by unchecking it under the “General” tab. That way any user will be required to login with a user account with full credentials and a password – even if they reboot the computer (remember to have the Guest account configured so that you will gain the Find My Mac protection offered through it in the odd event the computer is stolen, making it trackable from the web, another Mac, or iOS device that has Find My iPhone installed.)
Several users confuse this with the Screensaver option. Automatic Log Out will close applications and documents of the logged in user, while saving the last state of OSX so that everything will resume back to where it was once the user is logged again. This frees up system resources for other users, and allows other users to log into the computer if it’s multi-use.
Screensaver locks only bring a protective layer over current actions and don’t log anything out, all apps continue to run in the background and documents remain open. Because the user stays logged in, it does not free up resources by closing out apps of that user, and it also does not allow another user to login to the Mac.
In short, the screensaver approach is perfect for quick away-from-keyboard moments, while the automatic log out is better for extended periods away from a desk, particularly in corporate or educational environments.