How to limit the number of user system sessions

From Wiki-UX.info
Jump to: navigation, search

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

        MAXSESSIONS=5

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

   # Message of the day

        if [ -r /etc/motd ]
        then
                cat /etc/motd
        fi
...


Reference[edit]

NUMBER_OF_LOGINS_ALLOWED

    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