1

May someone please show me how I would restrict accounts/people logging into an ubuntu 10.04 server by SSH to a single active session at a time for each account that logs into the server.

Regards

1

If you look at man sshd_config, you can see that there is an option for MaxSessions. Unfortunately, this is the maximum number of sessions per network connection, not the maximum number for a specific user.

One thing you can do is set UsePAM yes in /etc/ssh/sshd_config, then configure PAM to handle the user limits by enabling the PAM module pam_limits.so. If you only want the limits to apply to ssh sessions, add the following line to /etc/pam.d/sshd:

session required pam_limits.so

I'm pretty sure all of the above stuff is the default configuration, now comes the part that actually sets the limit. pam_limits.so pulls its limits from /etc/security/limits.conf. If you want a user to only be able to have one active session at a time, just add the following line to that file:

user    hard    maxlogins    1

Once this is set up, on any log in attempt when there's already an active session, the user will get the error Too many logins for 'user'. To make this apply to all users, use * for the user. You can also have it apply to certain groups, for instance, use @users to apply to rule to everyone in the users group.

| improve this answer | |
  • Any results? Did this do what you wanted? – KevinC Jan 13 '14 at 21:06
  • how do. No it did not achieve what i wanted. even after making the changes i could still open multiple sessions for the same user at the same time – user232304 Jan 27 '14 at 13:54
  • Odd, it worked for me when I tested it. Can you paste the line you added to limits.conf? – KevinC Jan 27 '14 at 16:55
  • You are angel Kevin..there was a syntax error on my limits.conf line..it works..Thank you – user232304 Jan 29 '14 at 5:03
  • The answer provided by KevinC is correct. – user232304 Feb 1 '14 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.