ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Originally posted by scorbett You could also check to see if a directory named after the user exists in the /home directory.
This probably would not be the best way to determine if a user exists. Take for example the user root. It exists on all systems, yet most of the time the home directory for the root user in /root instead of /home/root.
Another example would be the rpm user (I'm using this since hindll01 is an RH user). rpm does not have an entry in the /home tree, but does exist.
slizadel is correct in pointing out that checking /home for the excistens of a user is not a good idea, although the second example could be a bit confusing.
In general there are 2 kind of users: system and regular.
Examples of system users are: root, bin, daemon, sshd, nobody, rpm. Most of the time they cannot (physically) log in to your box (root being the exception).
Regular users are those that can physically log in to a system. Most of the time these will be people like you and me.
The RH user mentioned in slizadel's thread is you. RedHat (RH) is nowadays called Fedora Core 1, which you might/might not know.
Most linux distro's use /home for the homedir location of regular users, but other locations can be used too and are legal.
Checking /home to see if a user excist is not failsafe.
You just opened a 8 year old thread to give an answer that was already given.
There's no reason to add to this long dead thread:
- The OP hasn't been seen since sept 2004,
- Multiple (better/simpler) answers have already been given.
In the most general case, you don't know how any particular system maintains its list of "recognized users." It could well be using LDAP or Kerberos. The best approach to problems like this is to attempt the operation and to trust the host system to reject a duplicate ... only he knows for sure.
Sorry! it wasn't marked as solved, and I noticed unSpawn, and Jan-Willem Arnold, had posted replies only 2 days shy of 5 years after the original post ( 09-10-04 -> 09-08-09 ). http://www.linuxquestions.org/linux/rules.html never mentions anything about "Necropost" so now that I'm aware of such an unwritten rule as a "Necropost" I'll just start new threads in the future, and make reference to the original post. Cool?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.