How to lock Mac using terminal?

Locking the Mac is a good way to prevent unauthorized access to it, so how do we lock the Mac using the terminal? Today, the editor will introduce to you the method of using the terminal to lock the Mac. Friends in need are welcome to refer to the operation!

Require password to unlock Mac

The command to lock the Mac using the terminal does not actually lock it. Instead, it just makes it into a sleep state. To be considered "locked", you must enter a password after logging in to the Mac to access the Mac. To password protect your Mac after it enters sleep mode, click the Apple icon at the top left of the menu bar and select "System Preferences."

Insert picture description here
Here, click "Security and Privacy".
Insert picture description here

Under the "General" tab, check the box next to "Require a password."

Enter your password and click the arrow next to "Require Password" to open the drop-down menu. You can then choose the amount of time that must pass before the password is required. Select "Immediately" to lock your Mac when it goes to sleep.

After enabling this feature, your Mac will be locked immediately whenever it goes to sleep.

Use terminal to lock Mac

To lock your Mac through the terminal, you must first start it. Press Command + Space to open Spotlight search. Type "Terminal" in the search bar and click on it when it appears in the search results.

In the Terminal, type the following command, and then press Enter:

pmset displaysleepnow

Your Mac will now enter sleep mode. If you selected the option that requires a password to wake it up, it is now also effectively locked. Locking your Mac is a great way to prevent unauthorized access to it, while still allowing programs to run in the background. If you want to terminate all operations, you can also shut down your Mac through Terminal.

The above is what the editor shared for you today. I hope it will be helpful to you. If you want to know more about Mac related content, please pay attention to macz.com!

Guess you like

Origin blog.csdn.net/macz_yo/article/details/113868865