1833049 Members
2453 Online
110049 Solutions
New Discussion

Re: User Session

 
SOLVED
Go to solution
Stefano_65
Regular Advisor

User Session

Hi guys..
how is it possible, if is it, to limit a user to only one session per time?.. I want that a particular user runs a single session, not more than one at the same time.

thanx.

st.
7 REPLIES 7
Bill Hassell
Honored Contributor
Solution

Re: User Session

With the latest security patches on 11.0 or 11.11 (specifically patches for /usr/bin/login), you can put this into /etc/default/security:

NUMBER_OF_LOGINS_ALLOWED=1


Bill Hassell, sysadmin
Bill Hassell
Honored Contributor

Re: User Session

Note: this is for ALL users except root. For a single user to be restricted, you'll need to script the test in /etc/profile or /etc/csh.login.


Bill Hassell, sysadmin
Stefano_65
Regular Advisor

Re: User Session

thanx dude

Stefano_65
Regular Advisor

Re: User Session


--
Note: this is for ALL users except root. For a single user to be restricted, you'll need to script the test in /etc/profile or /etc/csh.login.
--

ehm.. but how I can do that?
Bill Hassell
Honored Contributor

Re: User Session

For POSIX shell, ksh, bash, etc users, add this at the top of /etc/profile just after the trap statement:

for ONESESS in bill joe carol jenny
do
CURRLOGIN=$(who -u | grep -c ^$ONESESS)
if [ $CURRLOGIN -ge 2 -a $(id -un) = $ONESESS ]
then
echo "\n\nNo more sessions allowed:"
ps -f -u $ONESESS
sleep 5
exit
fi

where: bill joe carol jenny
are the users that are only allowed 1 session. Expand/change that list as needed.


Bill Hassell, sysadmin
Sundar_7
Honored Contributor

Re: User Session

There is a done missing at the end of the above script excerpt.

Here is an alternate way of doing it

define all the users in a file say /etc/ONLYSINGLESES

# vi /etc/ONLYSINGLESES
user1
user2
user3
#

# vi /etc/profile

grep -qi "^${LOGNAME}$" /etc/ONLYSINGLESES >/dev/null 2>&1

if [ $? -eq 0 ]
then
COUNT=$(who -u | grep "^$LOGNAME " | wc -l)
if [[ $COUNT -gt 1 ]]
then
echo "Only one session allowed for user: $LOGNAME"
sleep 2
exit
fi
fi

couple of advantages to the above excerpt

1) You dont have to execute the loop for all the users all the time.

2) You can dynamically define the list in the file than having to edit the script when the changes are to be mode.


Learn What to do ,How to do and more importantly When to do ?
Stefano_65
Regular Advisor

Re: User Session

thanx guys!!!!