Monday, May 21, 2012

To kill / delete remote login session in Linux

Solution:            
Check login user list:
# users
# last
# who
# w
Or,
First locate the process, for example, user logged in using ssh.
# ps -ef | grep ssh
Or,
Check process ID of users
              # ps -fu username
Kill the process    
# kill -HUP parent_processid
Or,
# skill -STOP -u username
# skill -CONT -u username
# skill -KILL -u username
Command to kill and logout all users as below
# skill -KILL -v /dev/pts/*
Or,
# pkill -STOP -u username
# pkill -CONT -u username
# pkill -KILL -u username

To set default session timeout / automatically logout inactive SSH sessions in Linux

Solution 1:
Edit the /etc/ssh/sshd_config file to set the parameter as follows:
# vi /etc/ssh/sshd_config
ClientAliveInterval 3600
ClientAliveCountMax 0
# service sshd reload          or,  
# service sshd restart
Solution 2:
The /etc/bashrc file is used to apply the timeout system wide but if you need it to be user specific then modify the ~/.bashrc file instead and add as below:
# echo "TMOUT=3600 >> /etc/bashrc
# echo "readonly TMOUT" >> /etc/bashrc
# echo "export TMOUT" >> /etc/bashrc
Log off, start a new session and wait for One Hour. Your session should terminate.