How to Log Out of Your Mac Using Terminal

Configurare noua (How To)

Situatie

Apple makes it easy to log out of your Mac with the option in the desktop’s menu bar. But there are also a couple of commands you can use to log out using Terminal, as we’ll discover today.

Solutie

Pasi de urmat
Terminate the loginwindow Process
  • To get started, you’ll need to open Terminal. You can quickly do this using Spotlight Search.
  • Click the magnifying glass icon to the right of the desktop’s menu bar (or press Command+Space) to launch Spotlight Search.

The Spotlight Search bar will appear. Type “Terminal,” and then press the Return key or click “Terminal” in the search results.

Search for "Terminal" in Spotlight Search and press "Return."

Terminal will launch. Now, run this command:

sudo pkill loginwindow

Run the "sudo pkill loginwindow" command.

Next, enter your account password and press the Return key.

Enter your account password.

This will terminate the loginwindow process, successfully logging you out of your user account.

Use a launchctl Command

launchctl commands are a set of commands that control the launchd process. You can find a list of launchctl commands by running launchctl help in Terminal, but we want to use the one that logs you out of your user account.

Before we start typing commands, you’ll need to know your user ID. To find it, open Spotlight Search (click the magnifying glass icon in the desktop’s menu bar or press Command+Space) and type “Users & Groups” in the search bar. Press the Return key or click “Users & Groups” in the search results.

Search and open "Users and Groups" from Spotlight Search.

Click the padlock in the bottom-left corner of the window that appears.

Click the lock.

Now, enter your account password and click “Unlock.”

Enter your password and click Unlock.

Next, right-click your account in the “Current User” group in the left-hand pane, and then click “Advanced Options.”

Right-click your user name and then click "Advanced Options."

Finally, take a note of your user ID. You’ll need this for the command.

Find your user ID.

With user ID in hand, open Terminal (use Spotlight Search to search for “Terminal” to open the app). In Terminal, run the following command (replacing <user id> with your ID noted earlier):

launchctl bootout user/$(id -u <user id>)

Run the launchctl bootout user command.

You’ll now be logged out of your user account.

This is just one of the many things that you can do with Mac’s Terminal. You can also do things like lock your Mac or even shut it down. Keep learning these basic commands and you’ll be a hacker in no time!

Tip solutie

Permanent

Voteaza

(9 din 18 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?