- How can I force other users to log out?
- 4 Answers 4
- Linux logout another user
- logout command syntax and example
- Task: Linux logout all other users
- pkill command syntax
- Linux Kill and Logout Users Command
- Linux Kill and Logout Users Command
- How To Halt/Stop a User Called vivek on Linux
- Resume Halted User Called vivek in Liuux
- Kill and Logout a User Called vivek under Linux
- Kill and Logout All Users
- The pkill command
- How to kill a Linux login session remotely
- Other useful nifty utilities provided by procps package
- Conclusion
- How To Logoff User Forcibly in Linux?
- List Logged On Users
- Logout From GUI or Desktop Environment
- logout Command
- Logout Current User
- How To Auto Logout Inactive Users After A Period Of Time In Linux
- Auto Logout Inactive Users After A Period Of Time In Linux
- Method 1:
- Method 2:
- Method 3:
- How To Logoff User Forcibly in Linux?
- List Logged On Users
- Logout From GUI or Desktop Environment
- logout Command
- Logout Current User
- How To Logout Logoff User Forcibly in Linux? Infografic
How can I force other users to log out?
Is there a simple way for me to force another user off of a linux box, while I am logged in as root? I understand that I could determine what type of session they have open, and kill the pid — but I’m thinking there must be a command to do this that I don’t know about. Any ideas?
4 Answers 4
Ha! Neat. I’d never heard of this command before. Is it available on all systems? Sure looks like it beats killing their shell process.
It’s probably packaged for all distros, but if you need something that works everywhere, skill from procps—as Mihai points out—might be a better choice. It has less style though 😉
Not installed on the Ubuntu 12.04 or RHEL 3 hosts that I have currently available, I do have the skill command detailed by Mihai Limbăşan. YMMV
You can kill all of an user’s processes via skill . Example:
will send SIGTERM to all of username ‘s processes. To kill them for good (via SIGKILL) use -KILL instead of -TERM — please note, though, that you will most likely cause them to lose data that way. It’s highly effective, mind you.
skill is part of the procps package which is installed by all distributions by default.
For others that want to do this for all remote user session, the -v flag ( -v pts/* ), which is from the man page might be useful.
The pkill and killall are preferred over skill . This is from the skill man page:
These tools are probably obsolete and unportable. The command syntax is poorly defined. Consider using the killall , pkill , and pgrep commands instead.
Another easy way to do it is to run kill -1 where pid is the process ID number of the SSH session.
By running this command, you can see all the sshd process trees, by killing the parent process ID you will effectively kill the user session associated with it:
Look for sshd and then run:
Where 39383 is an example of an arbitrary process ID number.
Linux logout another user
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.
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 Источник
Linux Kill and Logout Users Command
Linux Kill and Logout Users Command
The procps package contains utilities to browse the /proc/ filesystem, which is not a real file system but a way for the kernel to provide information about the status of entries in its process table. Procps includes the ps command, free command, skill command, pkill command, pgrep command, snice command, tload command, top command, uptime command, vmstat command, w command, watch command and pwdx command.
WARNING: Do not kill the process owned by the root user (UID 0) or PID 1. Keep in mind that killing necessary processes such as sshd or nfsd or httpd may result in the system downtown. Be careful with all commands. Think twice before entering any of the following commands.
How To Halt/Stop a User Called vivek on Linux
Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following commands. First, switch to the root user by typing the su — and entering the root password, when prompted (you can also use the sudo command if configured on your machine). Type the skill command as follows:
# skill -STOP -u vivek
The skill command sends a terminate command (or another specified signal) to a specified set of processes.
Resume Halted User Called vivek in Liuux
Send CONT single to user vivek, type the following command:
# skill -CONT -u vivek
Kill and Logout a User Called vivek under Linux
You can send KILL single, type the following command:
# skill -KILL -u vivek
Kill and Logout All Users
The ultimate command to kill and logout all users is as follows:
# skill -KILL -v /dev/pts/*
The pkill command
To halt or stop a user called vivek, enter:
# pkill -STOP -u vivek
Say you want to resume a user called vivek who was halted previously by the pkill command, enter:
# pkill -CONT -u vivek
Finally kill all php-cgi process owned by vivek user, enter:
# pkill -KILL -u vivek php-cgi
How to kill a Linux login session remotely
We can kill a Linux login session remotely by sending a hangup signal (SIGHUP) to the process running the login session. Typically BASH or KSH shell runs the login session. First, find out your current tty as we need to avoid killing ourselves. Type the tty command and press the [Enter] key:
# tty
Say you want to see all of the running processes of a user named wendy, enter:
# ps -fu
# ps -fu wendy
Look for the PID (process ID) in the second column. The sixth column shows the TTY to which your processes are connected. The last column gives a process name, which is a login shell. Finally, we are going to remove the remote shell. You must look for the shell PID and choose the PID that is not for your current tty and type:
# kill -HUP
Other useful nifty utilities provided by procps package
- w command : Show who is logged on and what they are doing.
- kill command : Send signal to a process (explains how to kill process under Linux)
- top command : Display Linux tasks and other important stuff
- vmstat command : Display virtual memory statistics.
- free command : Display free and used memory (RAM) statistics.
- slabtop command : Display kernel slab cache information in real time.
Conclusion
We cannot kill processes that are running on a Linux server other than the one you are logged into right now. For other remote Linux servers first, ssh into that box and run the above commands to kill users and log out of the systems. Set TMOUT to automatically log users out after a period of inactivity. See how to automatically logout BASH / TCSH / SSH users after a period of inactivity for more info.
How To Logoff User Forcibly in Linux?
We have some servers to manage. There are some user access to our server. We want to them log off or kill their processes by terminating. How can be achieve this?
List Logged On Users
We can logout other users forcibly like below. Keep in mind we need to be root to complete this command. First we will list currently logged in users with the who command. We can use w command alternatively to list users.
List Logged On Users
Logout From GUI or Desktop Environment
Different desktop environments provides GUI menus in order to logout from current session. In this example we will logout the user ismail from and XFCE desktop environment session. From right corner by clicking the user name we will list some menu which provides actions like Lock Screen , Suspend , Shutdown and Log Out . We can use Log Out button in order to logout from current user session.
Logout From GUI or Desktop Environment
logout Command
We can logout from current Linux user from terminal with the logout command.
logout Command
Logout Current User
We will use pkill command. This command will kill all processes owned by the given user with the -u option. In this example we know that the user ismail is logged in. We will log out the user ismail . We will also provide the -KILL option which will kill all processes related with the user ismail . Keep in mind that this will suddenly stop all this user related processes. This
- User -utest2 is logout
- pkill is the command which will send signals to the provided user processes
- -KILL is the kill signal to the specified user processes.
How To Auto Logout Inactive Users After A Period Of Time In Linux
Picture this scenario. You are managing a shared server that is regularly being accessed by many users from all systems in the network. There are chances that some user may forget to logout his session and left the session open. Leaving an user session open is dangerous and some users may misuse it intentionally. Would you manually check each and every system to verify whether the users have logged out or not? It is not necessary! Also, It’s quite time consuming task if there are hundreds of machines in your network. Instead, you can make an user to auto logout from a local or SSH session after a particular period of inactivity. This brief tutorial describes how to auto logout inactive users after a particular period of time in Linux and Unix-like systems.
Auto Logout Inactive Users After A Period Of Time In Linux
We can do it in three ways. Let us see the first method.
Method 1:
Add the following lines in it.
This makes the user to logout automatically after an inactivity of 100 seconds. You can define this value as per your convenient. Press ESC and type :wq to save and close the file.
Apply the changes by running the following command:
Now, leave the session idle for 100 seconds. After an inactivity of 100 seconds, you will see the following message and the user will be automatically logged out from the session.
This setting can be easily modified by the user. Because,
/.bashrc file is owned by the user himself.
To modify or delete this timeout settings, simply delete the lines added above and apply the changes by running «source
Alternatively, the user can disable this by running the following commands:
If you want to prevent the user from changing the settings, follow second method instead.
Method 2:
Create a new file called «autologout.sh».
Make it as executable using command:
Now, logout or reboot your system. The inactive user will automatically be logged out after 100 seconds. The normal user can’t change this settings even if he/she wanted to stay logged in the session. They will be thrown out exactly after 100 seconds.
These two methods are are applicable for both local session and remote session i.e the locally logged-in users or the users logged-in from a remote system via SSH. In the next method, we are going to see how to automatically logout only the inactive SSH sessions, not local sessions.
Method 3:
In this method, we will only making the SSH session users to log out after a particular period of inactivity.
Edit /etc/ssh/sshd_config file:
Add/modify the following lines:
Press ESC key and type :wq to save and close this file. Restart sshd service to take effect the changes.
Now, ssh to this system from a remote system. After 100 seconds, the ssh session will be automatically closed and you will see the following message:
Now, whoever access this system from a remote system via SSH will automatically be logged out after an inactivity of 100 seconds.
How To Logoff User Forcibly in Linux?
We have some servers to manage. There are some user access to our server. We want to them log off or kill their processes by terminating. How can be achieve this?
List Logged On Users
We can logout other users forcibly like below. Keep in mind we need to be root to complete this command. First we will list currently logged in users with the who command. We can use w command alternatively to list users.
Logout From GUI or Desktop Environment
Different desktop environments provides GUI menus in order to logout from current session. In this example we will logout the user ismail from and XFCE desktop environment session. From right corner by clicking the user name we will list some menu which provides actions like Lock Screen , Suspend , Shutdown and Log Out . We can use Log Out button in order to logout from current user session.
logout Command
We can logout from current Linux user from terminal with the logout command.
Logout Current User
We will use pkill command. This command will kill all processes owned by the given user with the -u option. In this example we know that the user ismail is logged in. We will log out the user ismail . We will also provide the -KILL option which will kill all processes related with the user ismail . Keep in mind that this will suddenly stop all this user related processes. This
- User -utest2 is logout
- pkill is the command which will send signals to the provided user processes
- -KILL is the kill signal to the specified user processes.