Ask Different Asked by prateeak ojha on November 23, 2021
I want to logout my Mac OS X from the command line. My OS X version is 10.9.
I tried command pkill -KILL -u uid
, but this command didn’t work out.
Is there a command that can be used to log out a user from the system using command line only, not AppleScript?
Try killing the loginwindow
process belonging to the user. Since all process belonging to the user is managed by loginwindow
, killing the loginwindow
process should log the user out.
Answered by Joy Jin on November 23, 2021
This does the trick for me
sudo -su user
and for root
sudo -su root
Answered by Karol Kowalski on November 23, 2021
An extreme way to kick the user session out is to force a restart:
sudo shutdown -r now
This works out well if you are trying to update the system.
Answered by MichaelDarkBlue on November 23, 2021
A nice utility to add to your Terminal is the "logout" command, to be used like:
logout UserName
Here the how to:
Edit your .bash_profile
nano ~/.bash_profile
Add this line:
logout() {sudo launchctl bootout user/$(id -u "$1")}
Save the file pressing ctrl+x
Restart the terminal
You are ready to go ;)
Answered by Kappe on November 23, 2021
sudo launchctl bootout gui/$(id -u <username>)
or
sudo launchctl bootout user/$(id -u <username>)
Replace username with the target user's user name or replace the whole subshell with the user's uid. This tells launchctl to teardown the users login session (gui specifically refers to the user's temporary login session, user specifies the users background processes).
You can log yourself out without the sudo
to test this.
Note that this will ONLY work on macOS 10.11.x or newer (see launchctl help
for more)
Answered by Iain Henderson on November 23, 2021
if you're logged with ssh to a remote computer you can logout by simply typing 'exit':
[host:~user]$ exit
Answered by holbein on November 23, 2021
This does the trick for me.
sudo -s
To get some root privileges and the # prompt, then kill the processes.
killall -vu username -HUP
And if it´s not all gone. Nuke em! Obligatory warning - killing things as root has no undo and no "are you sure you want to interrupt this process without saving your files, including system critical databases that might render the machine unbootable on rare occasion." type warnings.
killall -vu username -9
Answered by tovare on November 23, 2021
If you have multiple users ....
Find the Process ID with:
ps aux|grep login
Then kill that process and you logged that session out. But there are a lot of procceses left.
Check with pstree
so you know which process to terminate.
Answered by Hugo van der Kooij on November 23, 2021
To log out purely from terminal (or a remote ssh session), just kill the loginwindow process:
sudo pkill loginwindow
You could get fancy and specify the user if multiple users have a loginwindow process, but this is an easy one shot, no prompt way to end a user's graphical session.
Answered by bmike on November 23, 2021
This has worked for me in the past:
Log out (with confirmation)
osascript -e 'tell app "System Events" to log out'
Log out directly (no confirmation)
osascript -e 'tell app "System Events" to «event aevtrlgo»'
or
osascript -e 'tell application "loginwindow" to «event aevtrlgo»'
This way any running application will get noticed and can terminate in a safe fashion.
Answered by nohillside on November 23, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP