Operating System - HP-UX
1832959 Members
2978 Online
110048 Solutions
New Discussion

Re: Telnet sessions limit by user.

 
SOLVED
Go to solution
Jose Cristovao
Occasional Contributor

Telnet sessions limit by user.

I need to limit the number of telnet sessions opened by the same user.
Jose Cristovao
5 REPLIES 5
Steven E. Protter
Exalted Contributor
Solution

Re: Telnet sessions limit by user.

Run a little script with cron on a regular interval:

ps -ef | grep telnetd | awk '{print $1} > /tmp/file

while read -r username
do
numsession=$(ps -ef | grep $username | grep telnetd | wc -l)
if [ numsession -gt 1 ]
then
pid=$(ps -ef | grep $username | awk '{print $2}')
kill $pid
fi
done < /tmp/file

Some code modification required for smooth operation. Depending on the application that is being used, you may need to add code to handle smooth session shutdown.

Even better: in /etc/profile

telsession=$(ps -ef | grep $LOGNAME | grep telnetd| wc -l)

if [ telsession -ge 1 ]
then
echo "already logged in, one session per customer"
sleep 15
exit
fi

Take out the sleep to avoid user breaking to the shell.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Doug O'Leary
Honored Contributor

Re: Telnet sessions limit by user.

Hey;

The /etc/profile mod is probably the best bet; however, it doesn't take into account other access methods such as ssh or rlogin. You could run a ps -ef | grep ${user} | grep ksh to find out if the user has an active shell. Another good modification would be to have an exclusion list. For instnace, sysadmins and dbas could be allowed to have multiple sessions while normal users are only allowed one.

If you're absolutely sure that the only access method is telnet, then the /etc/profile mod as written will do what you want.

HTH;

Doug

------
Senior UNIX Admin
O'Leary Computers Inc
linkedin: http://www.linkedin.com/dkoleary
Resume: http://www.olearycomputers.com/resume.html
Gopi Sekar
Honored Contributor

Re: Telnet sessions limit by user.


if you want it instantaneous then put it /etc/profile

or from a cron job:

w | wc -l

minus the count by 2 to take care of the title output of w

then take the decision

Regards,
Gopi
Never Never Never Giveup
DCE
Honored Contributor

Re: Telnet sessions limit by user.

You can set the max number of logins allowed per non root user in /etc/default/security. You simply set NUMBER_OF_LOGINS_ALLOWED=X, where X is the max number of telent sessions you want any user to have

Dave
Steven E. Protter
Exalted Contributor

Re: Telnet sessions limit by user.

Didn't know about that option in the security file.

Anyone test it?

SEP
Contact form that mail's me offline:
http://www.isnamerica.com/isninquire.shtml
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com