This article is from a FAQ concerning SCO operating
systems. While some of the information may be applicable to any OS,
or any Unix or Linux OS, it may be specific to SCO Xenix, Open
Desktop or Openserver.
There is lots of Linux, Mac OS X and general Unix info elsewhere on
this site: Search this site is the best
way to find anything.
For some reason, I often get requests to limit users to one login. I guess the people asking such questions have a reason for wanting to restrict logins this way. The only way to do it is to add a script to either /etc/profile or the particular user's .profile that tests to see if this user is logged in somewhere else. Something like this in /etc/profile will work:
IAM=`who am i | cut -d" " -f1`
COUNT=`w | cut -d" " -f1 | grep "^$IAM$" | wc -l`
[ $COUNT -gt 1 ] && exit 0
Similar tricks can restrict a user to a particular tty:
IAM=`who am i | cut -d" " -f1`
TTY=`tty`
[ $TTY != "/dev/tty07" ] && [ $IAM = "tony" ] &&
exit 0
And then there's always restricting login to root: put this in /etc/profile
IAM=`who am i | cut -d" " -f1`
[ -f /etc/nologin ] && [ $IAM != "root" ] && exit
0
When you need to restrict logins, just "touch /etc/nologin"; remove it when the need is over.
IN ALL CASES YOU HAVE TO CONSIDER THE EFFECT OF SINGLE USER LOGIN. Tests like this can prevent you from logging in from the CTRL-D single user mode prompt because "who am i" and similar commands will return nothing. Avoid that by using "who -r" to test the run level.
You can restrict root to a particular device by adding a line like
CONSOLE=/dev/tty01
to /etc/default/login (se "man M login").
ALWAYS CHECK THAT YOU STILL CAN LOGIN after adding anything to /etc/profile! Do this BEFORE you log out! It's very easy to screw up and lock yourself out, necessitating a single-user mode reboot.
/SCOFAQ/FAQ_scotec6restrictlogin.html copyright 1997-2003 (various) All Rights Reserved
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Wed Aug 13 03:14:55 2008: Subject: lelajels
also check http://unix.ittoolbox.com/groups/technical-functional/ibm-aix-l/restrict-user-login-2172339?cv=expanded., by lrojask
If you get errors on SCO, just comment the read statement or fix it if you prefer to prompt for a key
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar