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.
Table of Contents
Terminate the loginwindow Process
One way of logging out of your user account is by running a command to 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.
Terminal will launch. Now, run this command:
sudo pkill loginwindow
Next, enter your account password and press the Return key.
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.
Click the padlock in the bottom-left corner of the window that appears.
Now, enter your account password and click “Unlock.”
Next, right-click your account in the “Current User” group in the left-hand pane, and then click “Advanced Options.”
Finally, take a note of your user ID. You’ll need this for the command.
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>)
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!
RELATED: The Best "Just For Fun" Tricks Hidden in macOS' Terminal