Linux logout all sessions

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

Читайте также:  Отключение графической оболочки linux

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.

Читайте также:  Linux add admin user

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.

Читайте также:  Compare windows os mac os and linux os

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.

Источник

exit out of all SSH connections in one command and close PuTTY

Is there a way to back out of all SSH connections and close PuTTY in «one shot»? I work in Windows 7 and use PuTTY to SSH to various Linux hosts. An example of the way I find myself working:

SSH to host1 with PuTTY. banjer@host1:~> #. doin some work. ooh! need to go check something on host8. banjer@host1:~> ssh host8 banjer@host8:~> #. doin some work. OK time for lunch. lets close putty. banjer@host8:~> exit banjer@host1:~> exit Putty closes. 

Per above, any way to get from host8 to closing PuTTY in one shot? Sometimes I find myself up to 5 or 10 hosts deep. I realize I can click the X to close the PuTTY window, but I like to make sure my SSH connections get closed properly by using the exit command. I also realize I’m asking for tips on how to increase laziness. I’ll just write it off as «how can I be more efficient».

@UlrichDangel I have never used that before, but also a quick way to back out of connections quickly.

Are you really nesting ssh sessions 5 to 10 levels deep? Do you realize that’s creating a convoluted tunnel that bounces all packets in your ssh session through all of those hosts? Could you make the problem go away by simply not nesting ssh sessions?

@jw013 No, I did not realize that, but makes sense. Honestly, 5-10 levels was an exaggeration, but I was trying to illustrate my question of «how to cleanly exit out of Putty in one fell swoop.»

7 Answers 7

Try using the ssh connection termination escape sequence.

In the ssh session, enter ~. (tilde dot). You won’t see the characters when you type them, but the session will terminate immediately.

$ ~. $ Connection to me.myhost.com closed. 
The supported escapes (assuming the default ‘~’) are: ~. Disconnect. ~^Z Background ssh. ~# List forwarded connections. ~& Background ssh at logout when waiting for forwarded connection / X11 sessions to terminate. ~? Display a list of escape characters. ~B Send a BREAK to the remote system (only useful for SSH protocol version 2 and if the peer supports it). ~C Open command line. Currently this allows the addition of port forwardings using the -L, -R and -D options (see above). It also allows the cancellation of existing remote port-forwardings using -KR[bind_address:]port. !command allows the user to execute a local command if the PermitLocalCommand option is enabled in ssh_config(5). Basic help is available, using the -h option. ~R Request rekeying of the connection (only useful for SSH protocol version 2 and if the peer supports it). 

Источник

Оцените статью
Adblock
detector