Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Limit number of User Logins

Status
Not open for further replies.

Dervie

Programmer
Apr 8, 2009
8
JM
Hi I would like to limit number of logins for each user to once. I have a command that only allows me to see the number of logins, (finger -fq username), but i need to actually execute something, perhaps in etc/profile that prevents multiple login sessions by the same user (except for exempted ones). Can anybody help me with this?
 
I'm not sure I'd want to put this in /etc/profile. If you get it wrong, you might create quite a headache.
But, you could put a bit of logic in the users' .profile script to look for existing sessions and just exit if the number exceeds "1". This command would give you a number you could use in your test condition:
Code:
who|grep "^$LOGNAME "|wc -l
If the number is < 2, then let them run. Otherwise, exit.

Not a solution, just a starting point.

"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
You can check in the /etc/profile by puting in something like this:

USERNAAM=`logname`
LOGS=`who|grep $USERNAAM|wc -l`
if [ $LOGS -gt "1" ] && [ $USERNAAM != "root" ]
then
echo "
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!This user is already logged on !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
"
exit 0
fi


This will allow every user to login only once except for root.



Greetz, Wim. Please remember, The Netherlands is in a different timezone.
 
Just be aware that this line:

LOGS=`who|grep $USERNAAM|wc -l`

would cause a problem if you have an existing session for the user "bobsmith" and another user named "smith" tries to log on.

"Proof that there is intelligent life in Oregon. Well, Life anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top