1827976 Members
3039 Online
109973 Solutions
New Discussion

Limiting UNIX Logins

 
SOLVED
Go to solution
Gregg McWilliams
New Member

Limiting UNIX Logins

Is it possible to limit users to one system login?
8 REPLIES 8
Patrick Wallek
Honored Contributor

Re: Limiting UNIX Logins

I do not know offhand of an easy way to do it.

One thought that comes to mind is to put something in the users .profile of .?shrc file that would do something like 'who | grep username' and if a value is returned then do an exit so it terminates their session.
Madhu Sudhan_1
Respected Contributor
Solution

Re: Limiting UNIX Logins

One of the way to limit the number of users in a system is to work with "npty" Number of pseudo tty data structures) Kernel Parameter. Default value of this parameter is 60 change it 20 incase if you want 20 users to login. When 21st user tries to login, he gets a message "No Enought ptys available on the system".

Enjoy !

...Madhu
Think Positive
Alexander M. Ermes
Honored Contributor

Re: Limiting UNIX Logins

Hi there.
Try this in the default profile :

no_of_users=`ps -ef|grep -v root ( or other users that you need to run on the system like oracle or so )|grep -v grep |wc -l`
export no_of_users
#
if test "$no_of_users" -gt 20
then
tput clear
echo "More than 20 users logged in......"
echo "Number of users logged in: $no_of_users"
echo "exiting......"
sleep 2
exit 1
else
do something
fi

rgds
Alexander M. Ermes
.. and all these memories are going to vanish like tears in the rain! final words from Rutger Hauer in "Blade Runner"
Alexander M. Ermes
Honored Contributor

Re: Limiting UNIX Logins

Hi there.
Sorry, instead of ps -ef you better use who -u
to find out, how many users you have one the system
Rgds
Alexander M. Ermes
.. and all these memories are going to vanish like tears in the rain! final words from Rutger Hauer in "Blade Runner"
Rick Garland
Honored Contributor

Re: Limiting UNIX Logins

A method that was used to limit logins was doing a grget command.
The profile included specific groups that were limited to one login per user.
Paula J Frazer-Campbell
Honored Contributor

Re: Limiting UNIX Logins

Hi Gregg
One way to do it and be very specific for each user is to use the passwd file as a reference and give use user a tel number for the number of logins required.
So in their .profile see if they are logged in , count their logins and look at the passwd file, so if login is greater that passwd allow exit.

I had a script to do this but cannot find it.

I have used this method and it works file.

Paula
If you can spell SysAdmin then you is one - anon
Gregg McWilliams
New Member

Re: Limiting UNIX Logins

Hi everyone, Thanks for all the great inputs! I think maybe I was too general. I have had a request to be sure that no individual user was logged in more than one time on the system, not the total number of users on the system. I think I will try the .profile method to see if they are in...
Rodney Hills
Honored Contributor

Re: Limiting UNIX Logins

I use the following in each users .profile:

ps -fu$LOGNAME | awk -v MYPID=$$ -v UNAME=$LOGNAME -f check.dup.login

I can then tell the user he/she has another session running, and even ask if they would like to kill it.

I only look for sessions called "UV" (uniVerse) to count. See attached awk script.
There be dragons...