cancel
Showing results for 
Search instead for 
Did you mean: 

limit user login

SOLVED
Go to solution
Vogra
Regular Advisor

limit user login

Hi All!
we use Baan ERP on UX11.00. Each login (on Baan) generate one user process (called bshell). From Baan, we can't limit number of user login for specific user.
We can try to limit number of user login, limiting number of bshell process that exist on UNIX.
How can I limit number of user login using - for example - script shell?
Thanx.
We are spirits in the material world
8 REPLIES
Nick Wickens
Respected Contributor

Re: limit user login

Hi I limit logins by adding the number of logins permitted into the message area (field 5) of the /etc/passwd entries for each user (our field r looks like this - Doug Green,Mr,IT_TEAM,5 so this user is limited to 5 ksh sessions).

I then added the following to a seperate profile called by the initial login profile.



USER=$(whoami)
echo $USER|egrep -q '(informix|dba)'
if [ ! $? -eq 0 ]
then
trap "exec exit" INT
TMPLOG=/tmp/login_limit.tmp
DATE=$(date)
LIMIT=$(grep ^$USER: /etc/passwd|cut -d":" -f5|cut -d"," -f4)
COUNT=$(ps -fu"$USER"|grep "$USER"|grep "\-ksh"|grep -v grep|wc -l)
if [ $LIMIT -o $LIMIT -ne 0 ]
then
if [ $COUNT -gt $LIMIT ]
then
echo "Sorry you are only allowed $LIMIT session(s) - Press Enter \c"
read NOTHING
echo "$DATE - $USER with $COUNT shells active tried to exceed $LIMIT ses
sions" >> $TMPLOG
ps -fu"$USER"|grep "$USER"|grep -v grep >> $TMPLOG
exit
fi
fi
fi
Hats ? We don't need no stinkin' hats !!
RAC_1
Honored Contributor

Re: limit user login

Check the following

Put the following code in /etc/profile(at the end)
user_name=`who -u |grep "your_user_name"`

if [$LOGNAME = $user_name]
exit 0
fi

What I am doing with above code is checking exisinting login and if it matches with incming login it will logout.

Regards,
There is no substitute to HARDWORK
Vogra
Regular Advisor

Re: limit user login

Nick and Anil,

The users don't execute /etc/profile or .profile.
The users connect on Baan from WIN95 clients that connect to Baan on Unix and in it, check the /etc/passwd.
We are spirits in the material world
MANOJ SRIVASTAVA
Honored Contributor

Re: limit user login

Hi Claudio

This is what can be done:

edit /etc/profile

and put this lines in there:


loginid=`who am i | awk '{print $1}'`
export B=`who | grep loginid | wc -l`
if [ $B -gt 5 ]
then
exit
fi


this will allow only 5 users to login with that id.

Manoj Srivastava


RAC_1
Honored Contributor
Solution

Re: limit user login

do while true
bann_count=`ps -ef|grep [b]shell|awk '{print $2}'`

bann_count2=ps -ef|grep [b]shell|awk '{print $2}'` > /tmp/bann.test

kill -15 `cat /tmp/bann.test|grep -v $bann_count`
sleep 5
done

Keep the above code in a file and keep it running.

This puts the pid of first bshell in a variable and then keeps on checking if other bshells are coming and if gets it puts pids in file and finally kills all bshells except the first one-saved in bann_count variable.

Regards,
There is no substitute to HARDWORK
kevin leong
Frequent Advisor

Re: limit user login

Hi Manoj ,
I trying used your scripts and put in to /etc/profile at last line .And I try login again ,giving a syntax error .

You have mail.
/etc/profile[132]:Syntax error:`&' is not expected .

Please advice me how to slove it

Thanks
Leongko
Muthukumar_5
Honored Contributor

Re: limit user login

You can try do it simply as,

MAX_LOGIN=5
if [[ $(who | grep $LOGNAME | wc -l) -gt $MAX_LOGIN ]]
then

echo "User $LOGNAME: Login Limit $MAX_LOGIN is over. Try after some time"
sleep 1
exit 1
fi

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: limit user login

Put the above script in /etc/profile file to control globally.

hth.
Easy to suggest when don't know about the problem!