bash 如何使用 shell 从计算机注销?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2996525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I logout from a computer using shell?
提问by Usman
How can I log out of my computer using shell such the log-in window appears again?
如何使用 shell 注销我的计算机,以便再次出现登录窗口?
I need this functionality in one my Linux script.
我的一个 Linux 脚本中需要此功能。
Update: I want to replicate the code working behind the Logout button of my Ubuntu.
更新:我想复制在我的 Ubuntu 的注销按钮后面工作的代码。
Desktop Enviroment being used: GNOME
使用的桌面环境:GNOME
采纳答案by theDmi
I think this does the job:
我认为这可以完成工作:
gnome-session-save --logout
Also, take a look at the --help output, maybe you want to use the --force-logout option.
另外,看看 --help 输出,也许你想使用 --force-logout 选项。
Usage:
gnome-session-save [OPTION...]
Help Options:
-h, --help Show help options
--help-all Show all help options
--help-gtk Show GTK+ Options
Application Options:
--logout Log out
--force-logout Log out, ignoring any existing inhibitors
--logout-dialog Show logout dialog
--shutdown-dialog Show shutdown dialog
--gui Use dialog boxes for errors
--display=DISPLAY X display to use
回答by sleske
Your question is a bit vague. Are you trying to log out of a graphical session of a desktop environment (such as KDE/Gnome), as if the user clicked on "log off"?
你的问题有点含糊。您是否试图从桌面环境(例如 KDE/Gnome)的图形会话中注销,就像用户单击“注销”一样?
Then you need to find out if/how the desktop environment supports scripting to log out. On KDE for example you can use kquitapp.
然后您需要找出桌面环境是否/如何支持脚本注销。例如,在 KDE 上,您可以使用kquitapp.
回答by Edward Dale
Try restarting the display manager using one of the following, depending one which one you're using. You'll obviously have to have the proper permissions.
尝试使用以下方法之一重新启动显示管理器,具体取决于您使用的是哪一种。您显然必须拥有适当的权限。
/etc/init.d/xdm restart
/etc/init.d/kdm restart
/etc/init.d/gdm restart
回答by crazyscot
It's a bit of a hack, but the way that screen's power detach does this is to determine its parent pid and send it a SIGHUP. (Clarification: This closes only the shell, so only works if you're running from a console - not a graphical login - so may not be what you're looking for.)
这有点像hack,但是screenpower detach的方法是确定它的父pid 并发送一个SIGHUP. (澄清:这仅关闭外壳,因此仅当您从控制台运行时才有效 - 而不是图形登录 - 所以可能不是您正在寻找的。)
回答by mahe
Type in terminal
输入终端
gnome-session-quit
or
或者
pkill -kill -u {Username}

