How to limit the number of user system sessions
Jump to: navigation, search

How to limit the number of user system sessions

The following code snap can be use on /etc/profile to close the current login session if the MAXSESSIONS variable value is reach. Connection protocol or IP Address address is indistint.

   # This is to meet legal requirements...

        cat /etc/copyright

   # Close session if MAXSESSIONS less than the current user sessions


        if [ $(who | grep $(whoami) | wc -l) -gt ${MAXSESSIONS} ]; then
           echo "Max sessions per user ${MAXSESSIONS} reached. Closing current session..."
           sleep 2
           exit 1

   # Message of the day

        if [ -r /etc/motd ]
                cat /etc/motd


    This attribute controls the number of simultaneous logins allowed per user. Note that this is only enforced for non-root users and only applies to the applications that use session management services provided by pam_hpsec as configured in /etc/pam.conf, or those services that indirectly invoke login, such as the telnetd and rlogind commands. If the TrustedMigration product is installed, the system-wide default defined here may be overridden by defining a per-user value in /var/adm/userdb (described in userdb(4)).
    NUMBER_OF_LOGINS_ALLOWED=0 Any number of logins are allowed per user.
    NUMBER_OF_LOGINS_ALLOWED=N N number of logins are allowed per user.
    Default value: NUMBER_OF_LOGINS_ALLOWED=0
This page was last modified on 26 March 2011, at 07:36. This page has been accessed 1,022 times.