Apple makes it easy to log out of your Mac with the option on the desktop menu bar. But there are also a couple of commands that you can use to log out using Terminal, as we will find out today.
Terminate the login window process
One way to log out of your user account is to run a command to end the login window process . To get started, you will open Terminal . You can do this quickly using Spotlight Search.
Click the magnifying glass icon on the right of the desktop menu bar (or press Command + Space) to launch the spotlight search .
The Spotlight search bar will appear. Type “Terminal” and then press the Return key or click “Terminal” in the search results.
The terminal will start. Now, run this command:
sudo pkill loginwindow
Then enter your account password and press the Return key.
This will end the login window process and successfully log out of your user account.
Use a launchctl command
The launchctl commands are a set of commands that control the launchd process . You can find a list of launchctl commands by running them
launchctl help in Terminal, but we want to use the one that disconnects you from your user account.
Before we start writing commands, you will need to know your user ID. To find it, open Spotlight Search (click the magnifying glass icon in the desktop menu bar or press Command + Space) and type “Users and Groups” in the search bar. Press the Return key or click “Users and Groups” in the search results.
Click on the padlock in the lower left corner of the window that appears.
Now, enter your account password and click “Unlock”.
Next, right-click on your account in the “Current User” group on the left panel and then click on “Advanced Options”.
Finally, make a note of your user ID. You will need this for the command.
With the user ID in hand, open Terminal (use Spotlight Search to search for “Terminal” to open the application). In Terminal, run the following command (replacing
<user id> with your ID stated above):
launchctl bootout user / $ (id -u <id de usuario>)
Your user account will now be logged out.
This is just one of the many things you can do with the Mac Terminal. You can also do things like lock your Mac or even turn it off . Keep learning these basic commands and you’ll be a hacker in no time!