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 a user to 1 Login 1

Status
Not open for further replies.

costiles

Technical User
Jun 14, 2005
117
US
I would like to limit a particular user to only one login. Is that possible?
 
I think you could do it in /etc/security/login.cfg file
 
You could try this script that we use for users.

In the users .profile in there home directory put the below in.

##########################################################
# Check if user is already logged in as only one login is allowed
ME=`who am i | awk '{print $1}'`
echo $ME | grep "^userid" >/dev/null
if [ $? -eq 0 ]
then
LOGCNT=`who |awk '{print $1}'| grep "^$ME$"| wc -l`
if [ $LOGCNT -gt 1 ]
then
echo "Sorry, you are already logged in 3 times. Please finish current task and
echo then continue with the new task. You are now limited to 3 logins."
sleep 9
logout
fi
fi
###########################################################

Put it just below the "PATH=" statement in the .profile
The "username" you would put there id and in "if [ $LOGCNT -gt 1 ]" part change 1 to the amount of time you want them to have a session.

Hope you understand it.

thanks
 
Oops !!

change this part

########################################
then
echo "Sorry, you are already logged in 3 times. Please finish current task and
echo then continue with the new task. You are now limited to 3 logins."
sleep 9
logout
fi
########################################

to

#########################################
then
echo "Sorry, you are already logged in 1 times. Please finish current task and"
echo "then continue with the new task. You are now limited to 1 logins."
sleep 9
logout
fi
##########################################

Thanks
 
Thank you so much for your reply. I will put this into action!
 
If you're adding something to their personal .profile (which is a good idea), make sure only root can write to the profile, otherwise it's worthless.
 
Well, if that .profile is in their own (writable) directory, it's still easily circumvented. I prefer to put code like this in a central profile-script. Not necessarily in /etc/profile, but you could setup a central extension to /etc/profile which can be "sourced" at the end of /etc/profile, so whenever /etc/profile gets updated (upgrade AIX e.g.), you only need a minor alteration to get your code "back in business"...

Code:
...
export LOGNAME MAIL MAILMSG TERM

if [ -f /usr/local/etc/profile ]
then
 . /usr/local/etc/profile # site's extension to central profile
fi

trap 1 2 3



HTH,

p5wizard
 
that's a good idea, but if you only want to limit one user not all users, this would be a problem.
 
If you put a "case ${LOGNAME} in" or sth. around that piece of code then you're off...

HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top