- Linux Logout user / Logoff User Commands
- logout command syntax and example
- Task: Linux logout all other users
- pkill command syntax
- 4 Ways to Log Out of a Ubuntu Desktop Session
- Method 1: Log Out Using the UI
- Method 2: Log Out Using Keyboard Shortcut
- Method 3: Log Out Using the Application Launcher Search
- Method 4: Log Out Using the Terminal
- Karim Buzdar
- Automatically Logout Inactive Users From Linux System
- Method 1: Use TMOUT to auto logout users from idle shell sessions
- Method 2: Automatically logout users from idle SSH sessions
Linux Logout user / Logoff User Commands
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | pkill |
Est. reading time | 2m |
a) pkill command – Kill processes by name.
b) kill command – terminate or signal a process.
c) logout command – Logout of a login shell. This command can be used by normal users to end their own session.
logout command syntax and example
If you are logged in as nixcraft user and just wanted to exit a login shell type the following command or hit CTRL+D:
$ logout
You will be logout of a login shell session or secure shell session.
Task: Linux logout all other users
If you would like to logout other users, you must login as root user. Next you need to use the pkill command.
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
pkill command syntax
Warning : Do not kill root user or other system level user process. The following example, will kill all process on your server. Do not run the pkill for root user:
pkill -KILL -u root
To see list of logged in user type who or w command:
# who
OR
# w
To logout a user called raj, enter:
# pkill -KILL -u raj
OR
$ sudo pkill -KILL -u raj
See also
- For more information read our previous “Linux kill and logout users” tutorial.
- Man pages: pgrep(1)
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
Its one of things i hardly ever remember, never mind that i take the effort to write it down, but if you do need it a post like this is worth a million…
thanks
Works in OpenBSD 4.5 also. Great tip.
Whow, thanks for this posting! Just what I needed, highly appreciated!
Thanks, I was looking for such a command
i want to show the login time and logout time of all users then i will sort it according to their name help me pls…
Thanks a lot!
pkill worked fine in the GUI session!
Regards;
Thanks a lot.
I found here very usefull information about my quistions.
Best regards.
what’s the KILL flag do?
thanks, it works me to kill my locked sessions in a server
Hey, Thanks… This is exactly i requried.
Thanks you buddy….I have seen some of your posts regarding Linux commands. They are very useful for beginners like me.
if i logged twice from putty as same user root then if i want to logout one root user then how i would do it.As same user logged twice then in that case if i kill process of root -user then both will get kill…so is their is any ip based parameter to logout one root ?
Mark! do the work!
Wow. What bad information. Lets say you have root logged in under two sessions.
pkill -KILL -u root
That kills all processes owned by root. Meaning most system processes.
Let’s say you have one user in multiple sessions and that user is not root. Well, you just killed both sessions, even if that’s not what you wanted.
This is terrible advice, and the article should be called “Linux Kill All Processes by User”, and have nothing to do with “logging off”.
how The system should send an email alert when the root user has logged out from ssh/terminal.
@Scott, if you know the better command how to logout the user you could write it here, not just come and start wonder here how bed info that is!
How to identify which roles are running in Linux server by using Command line.
How to remotely GUI access linux gateway server .
I want to be able log multiple users off with a message without shutting down. Any thoughts?
ThanKs, comes handy when dude forgot to log out of his guest session here!
Yeah first time i found a usefull answer to my linux questions, : Ctrl + D
😀
Источник
4 Ways to Log Out of a Ubuntu Desktop Session
If you are using an Ubuntu system with multiple users and one of the other users asks you to use the system, you have two options for giving the system to him. One is to switch users, and the other is to log out of your user session for the other person. The difference between the two is that when you switch users, your current session continues to run in the background and you can restore your applications to the same state when you log back in. However, when you log off, your current session is terminated and all running applications are stopped. So when you log back in, you will have to reopen all the applications you need. You can choose between switching users and logging off, whichever suits you at the time.
In this article, we will describe four ways using which a user can log out of his/her Ubuntu session:
- Using the UI
- Using the Keyboard shortcut
- Through the application launcher search bar
- Through the Ubuntu command line, the Terminal
We have run the commands and procedures mentioned in this article on a Ubuntu 20.04 LTS system.
Method 1: Log Out Using the UI
One of the simple ways to log out of your Ubuntu session is to use the menu accessible through the downward arrow located at the top right corner of your Ubuntu screen. This is the menu you will see when you click this arrow:
Click your username and you will be able to see the following two main sub-menu items: Log Out and Account Settings. Click on the Log Out option in order to log out of your current Ubuntu session. The following dialog will display if you do so:
This dialog lets you log out right then by clicking the Log Out button. Otherwise, the system automatically ends your session after 60 seconds unless you press the Cancel button.
Method 2: Log Out Using Keyboard Shortcut
Ubuntu comes with a set of default keyboard shortcuts that allow you to perform commonly used Ubuntu operations with keyboard shortcuts. Logging out, a very common operation is also assigned such a keyboard shortcut. When you press the key combination Ctrl+Alt+Del, the same logout dialog we described above is displayed.
You can see all of these keyboard shortcuts and even create your own using the System Preferences utility. Open the Preferences utility directly from the Keyboard view by typing the word “keyboard shortcuts” into the search bar of your application launcher as follows:
Click on the Keyboard search result and you will be able to see the following view: Advertisement
Method 3: Log Out Using the Application Launcher Search
Another quick method to log out of your session is to use the very useful application launcher search bar. This bar can be accessed by hitting the Super/Windows key on your keyboard.
Enter the keyword “logout” in this search bar and you will see the Log Out utility in the search result as follows:
Click on the Log Out search result and you will be presented with the same Log Out dialog that we described above.
Method 4: Log Out Using the Terminal
For a Terminal-savvy person, the Ubuntu command line also provides a way to log out of your Ubuntu user session.
Open the Ubuntu command line, the Terminal, either through the application launcher search or the Ctrl+Alt+T shortcut.
Then enter the following command in order to end the current user’s login session:
When you run this command, a dialog appears that lets you log out right then by clicking the Log Out button. Otherwise, the system automatically ends your session after 60 seconds unless you press the Cancel button on this dialog.
If you want to directly log out without having to see this dialog, you can make use of the following command:
So, these were some ways you can use to safely log out of your Ubuntu user session so that another user can use the system after you.
Karim Buzdar
About the Author: Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn
Источник
Automatically Logout Inactive Users From Linux System
Keeping idle shell sessions to a Linux server is possible a security risk. Not to forget that it would consume system resources.
Okay, maybe not a single idle session but imagine if you have multiple users accessing the same Linux system remotely and leaving their sessions idle.
As a Linux sysadmin, you can see which users are logged in on the system and how long have they been idle.
You may manually kick the idle user out but that’s tiresome and certainly not very productive.
Let me show you how to automatically logout idle users from their shell.
Method 1: Use TMOUT to auto logout users from idle shell sessions
In bash and other shells, you can use the TMOUT variable to set the idle logout time. If there is no activity from the user for this time period, the shell session will be closed.
Check if the TMOUT is already set. The values are in seconds.
To test, you can use it like this:
This will close your terminal session or SSH session after 300 seconds, i.e. 5 minutes.
For SSH sessions, you should see a message like this:
For local sessions, your terminal should be closed automatically.
But you probably already know that it is not the best way to set an environment variable. You can either set it in individual user’s profile (or bash profile) or you set it for all the users, system wide, from /etc/profile.
Assuming that you are a sysadmin and you want to auto logout idle users on your Linux server, set it at system level.
Open the /etc/profile file in a text editor like Vim or Nano:
And add the following line to it:
Save and close the file. From now onward, any user with 5 minutes of inactivity will be logged out automatically.
This works for both local and remote sessions. If you want to set it only for SSH sessions, the next method is what you could use.
Method 2: Automatically logout users from idle SSH sessions
You can configure SSH server to force logout a user after certain inactivity period.
Edit the SSH config file (/etc/ssh/sshd_config):
Look for the following two variables and remove the # before their starting line and set values like this:
Save and close the file.
This means that the server will send a keep alive message to the client every 200 seconds for 3 times. If it receives no response (meaning the user is idle), it will close the session at 600 seconds (200*3).
You can choose suitable values based on your requirement.
This is SSH only method and will not impact the local shell sessions.
I hope you find this Linux tip on automatically logging out users helpful. Do subscribe for more Linux sysadmin tips.
Источник