Solved

bash script to count red hat linux concurrant logins

Posted on 2015-01-12
8
254 Views
Last Modified: 2015-01-13
Our server run red hat Linux AS 5.4 with over 700 users connected.  We would like to limit users to 3 concurrent logins.  Red hat support has told me there is no built in method for limiting users to 3 concurrent logins.  

1.  Is Red Hat support correct, is there a way to limit user logins to 3 concurrent logins?
2.  Is there a simple way to identify users with multiple concurrent logins?

Thanks
0
Comment
Question by:epmmis
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 48

Accepted Solution

by:
Tintin earned 400 total points
Comment Utility
Edit /etc/security/limits.conf and set

*      hard maxlogins 3
0
 
LVL 23

Expert Comment

by:savone
Comment Utility
How are the users logging in?  Is it via SSH?

You can run something like this to see how many people are logged in:

for i in `cat /etc/passwd | cut -d: -f 1`; do u=`who | grep -c $i`; echo $i has $u concurrent logins; done
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 100 total points
Comment Utility
To find out how many logins per user, run

who | awk '{ print $1 }' | uniq -c
0
 
LVL 23

Expert Comment

by:savone
Comment Utility
@omarfarid, I like it! Very clean output!  Seems to taught two people something today and this is why I love Experts Exchange.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:epmmis
Comment Utility
TinTin - I am now looking into using /etc/security/limits.conf to limit the concurrent logons.  Any advice about implementing the limit?  Does the server need to be rebooted?

@omarfarid - thanks for the script It is easy and clean output.  

@savone - I tried your code on the command line.  The for loop did not work.  I have yet to put the code in a script.
0
 
LVL 40

Expert Comment

by:omarfarid
Comment Utility
Thank you all :)

Since I started participating in Experts Exchange my skills and knowledge improved a lot.
0
 
LVL 48

Expert Comment

by:Tintin
Comment Utility
Pretty certain you don't need a reboot after changing limits.conf

Easiest way is to just try.
0
 

Author Closing Comment

by:epmmis
Comment Utility
TinTin - you get 400 points because your answer is spot on.
 omarfarid - you get 100 points because your script will help me identify the users which need to be controled by the limits.conf file.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now