LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 09-24-2010, 12:28 AM   #1
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Rep: Reputation: 18
Log off or Log out a User By running a Command


Hi,


Let's say 4 users have logged in on 4 different Virtual Consoles:

tty1 .... tty4

On tty4 is logged in User4.

How can I log out the User4 from my console using the root login?

I just checked out the man page of shutdown but didn't find any hint there.

The logout command is also not doing the work. We cannot specify a username wit it to log him/her out.
 
Old 09-24-2010, 04:32 AM   #2
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,669

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
Quote:
On tty4 is logged in User4.

How can I log out the User4 from my console using the root login?

I just checked out the man page of shutdown but didn't find any hint there.

The logout command is also not doing the work. We cannot specify a username wit it to log him/her out.
While you are logged in as superuser/root you can use 'kill' command.

1. Know the UID in tty4:
root@host-# w (this will return list of all logged users in the machine)

2. Kill the process ID (PID) belonging to him:
root@host -#ps axu | grep USER
root@host-# kill N (where N =the PID number of the user you want to kick out)

3. If he has taken hold of X while you are at the shell you can kill the X process ID
root@host-# top (this will show X pid) press "K" then write the X PID, press Enter.

If you want to close all files opened by the user you can find them all using "lsof | grep 'username'" then proceed to kill all of it. Just be careful of this.

Hope it helps.
 
Old 09-24-2010, 04:32 AM   #3
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,669

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
I thought you mean "remote" logged?

You can use "kick".

Last edited by malekmustaq; 09-24-2010 at 04:58 AM.
 
Old 09-24-2010, 07:17 PM   #4
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by malekmustaq View Post
While you are logged in as superuser/root you can use 'kill' command.

1. Know the UID in tty4:
root@host-# w (this will return list of all logged users in the machine)

2. Kill the process ID (PID) belonging to him:
root@host -#ps axu | grep USER
root@host-# kill N (where N =the PID number of the user you want to kick out)

3. If he has taken hold of X while you are at the shell you can kill the X process ID
root@host-# top (this will show X pid) press "K" then write the X PID, press Enter.

If you want to close all files opened by the user you can find them all using "lsof | grep 'username'" then proceed to kill all of it. Just be careful of this.

Hope it helps.


Well, I thought there would be a command to accomplish it straightforwardly.

Anyways, thanks for the suggestion. Can you suggest a method of killing a process which has multiple Process IDs?

For example, user_zero logs in using the shell bash. The user_zero execute the command: "vi fileName".

We see in the output of

ps aux | grep user_zero

that there are two PIDs- one for -bash and the other for "vi filename".

So, "killall -u user_zero" would only terminate the editor and log off the user. We need to kill the PID of "-bash" also.

Is there any single command to kill all the PIDs of a single User or Command or Service?


Okay, I just tried:

killall -9 pid_of_"-bash"

and the user is logged out.

Last edited by Hi_This_is_Dev; 09-24-2010 at 07:20 PM.
 
Old 09-24-2010, 10:05 PM   #5
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by Hi_This_is_Dev View Post
Okay, I just tried:

killall -9 pid_of_"-bash"

and the user is logged out.
- No need to use 'killall', 'kill' is enough.
- Because of bash is parent process (check with ps -ef | grep pts\/x). Killing the parent will kill its children as well.
 
Old 09-25-2010, 02:43 AM   #6
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,669

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
Quote:
Is there any single command to kill all the PIDs of a single User or Command or Service?
As 'quanta' stated above so it is: "Kill the mother, and the children die." Or have you not read, it is written: "I shall strike the shepherd and the flock is scattered."

So how would you know which is the mother and which are the children?

GNU has made it simple for you to know. Issue either of these commands in the terminal and you shall see the picture of the process tree:

Hi_There@host--# ps -ejH (or this one..)
Hi_There@host--# ps -axjf

Hope this helps. Good luck.

Last edited by malekmustaq; 09-25-2010 at 02:45 AM.
 
Old 09-25-2010, 02:53 AM   #7
malekmustaq
Senior Member
 
Registered: Dec 2008
Location: root
Distribution: Slackware & BSD
Posts: 1,669

Rep: Reputation: 498Reputation: 498Reputation: 498Reputation: 498Reputation: 498
Quote:
that there are two PIDs- one for -bash and the other for "vi filename".

So, "killall -u user_zero" would only terminate the editor and log off the user. We need to kill the PID of "-bash" also.
Where effective user was able to deploy multiple threads there shall be many processes bearing children and possible grandchildren. This means you are not engaged against a family alone but killing you have to kill the entire clan.

To control the system is the work of the admin. Looking ONLY for a single magical command is like a lazy man waiting for a miracle to happen. And I can only give you one miracle to eradicate all processes in one command: 'Ctl+Alt+Del' !

Hope this helps.
 
Old 09-25-2010, 06:37 PM   #8
Hi_This_is_Dev
Member
 
Registered: May 2009
Location: India
Distribution: On my PC I use RHEL, at office AIX, Solaris, HP-UX, RHEL.
Posts: 254

Original Poster
Rep: Reputation: 18
Quote:
Originally Posted by malekmustaq View Post
"I shall strike the shepherd and the flock is scattered."


Divide and Rule! - The Britishers taught India long ago.
 
  


Reply

Tags
log off, logout, remotely



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Log off/log on as different user breaks X apps under Debian 5.0.1 lbdu Debian 1 06-26-2009 05:54 AM
a command or way to log time of iptables LOG entries? dividingbyzero Linux - Security 3 06-06-2008 01:23 AM
Command to log a user out? Or restart X within a script? BogusTrumper Linux - Desktop 1 06-29-2007 02:05 PM
How to log off a user from command line raazman Linux - General 3 05-11-2007 07:43 PM
Running command when I log into WindowMaker chrisk5527 Linux - General 1 10-16-2004 02:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 09:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration