Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a special lab machine (linux) and two different users will be using this machine. They need to log in with the same userid. I want to prevent both of them from logging in at the same time. How can I do that?

I was thinking of starting with something simple like this - Use the users source IP-address and add some checks in .bashrc :

If a user logs in from IPAddress1 and there is already somebody ssh'ed in from IPAddress2 then print a big fat message.

share|improve this question
up vote 8 down vote accepted

You can use pam_limits to do this too. Add a line like

fred    hard    maxlogins    1

to /etc/security/limits.conf and it will only allow the user fred to log in up to 1 (maxlogins) times.

share|improve this answer
that's a better solution than mine. – Sirex Feb 14 '12 at 11:56

I think your plan sounds reasonable. Maybe do a check against something like last [username] | grep "still logged in" | wc -l in bashrc ? - could check for the ip there, also.

share|improve this answer
perfect. I did not know about last. last -d is what I will use. Thanks. – MK. Feb 14 '12 at 11:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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