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.

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.

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.

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.

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!

RELATED: The Best "Just For Fun" Tricks Hidden in macOS' Terminal

Profile Photo for Marshall Gunnell Marshall Gunnell
Marshall is a writer with experience in the data storage industry. He worked at Synology, and most recently as CMO and technical staff writer at StorageReview. He's currently an API/Software Technical Writer based in Tokyo, Japan, runs VGKAMI and ITEnterpriser, and spends what little free time he has learning Japanese.
Read Full Bio »