Operating System - HP-UX
1837266 Members
2425 Online
110115 Solutions
New Discussion

Unexpected behaviour of useradd

 
SOLVED
Go to solution
Olivier ROBERT
Frequent Advisor

Unexpected behaviour of useradd

Dear forum readers,

I discovered only recently the following, and unspecified, behaviour of useradd.

I have a user account named "src" whose home is /home/src, and I need to create another one, named "srctm", with the same home directory. So I created it:

# useradd -u -g srctm -d /home/src -s /usr/bin/ksh srctm

... and I was very disappointed, least to be said, to discover that useradd horribly chowned -R srctm:srctm /home/src, which contains thousands of files eventually. I really would have liked this to be documented, but it is not. Hence, there is a bug somewhere, either in the docs, or in the code... or did I miss something?

What are your opinions about that? Is there a way to perform a useradd without that chown? I think that behaviour should be removed, since it is not specified.

Thanks for your help!

Olivier
13 REPLIES 13
T G Manikandan
Honored Contributor

Re: Unexpected behaviour of useradd

Yes,it should.
When you add the user in SAM
it will give a alert for the existing home directory used by another user.

As for command line it does that silently.

As far as I know You cannot use the same home directory for two users.
the directory ownership will be only for one user.



Thanks
Ravi_8
Honored Contributor

Re: Unexpected behaviour of useradd

Hi,

I don't agree with having same home dir for 2 uid's. as usual recently created uid will be owner that home dir
never give up
Olivier ROBERT
Frequent Advisor

Re: Unexpected behaviour of useradd

Thanks for your replies,

I know that having two users share the same home directory is not common, but I have special needs, since that second user should get an environment chrooted to the first user's home directory (I changed the user's shell to * eventually), hence the need to set the user's home directory to that of the first user.

Any HP representative willing to reply "We're working on that"? That would be worth ten points! :o)

Regards,

Olivier
Christopher Caldwell
Honored Contributor

Re: Unexpected behaviour of useradd

You could write your own "useradd" that meets your requirements; a customer useradd would be trivial for a non-trusted system and nearly trivial for a trusted system.

Cheryl Griffin
Honored Contributor
Solution

Re: Unexpected behaviour of useradd

There is an ER for useradd to allow shared directories, 5003407825 and a patch (not released yet) that will update the man page for useradd PHCO_26756 warning of this until the ER can address the issue.

If you use SAM this is not a problem.
SAM --> add the shared home directory and uncheck the box that says
[ ] CREATE HOME DIRECTORY

SAM will also display a warning:
Directory "/home/cherylg" already exists. If you set the "Create Home Directory" toggle, SAM will change the permissions on this directory to match the new user and will copy default configuration files into the directory, possibly overwriting existing files. If you do not set the "Create Home Directory" toggle, SAM will not change the permissions on this directory nor will any configuration files be copied into the directory.

Would you like to use this home directory?
"Downtime is a Crime."
T G Manikandan
Honored Contributor

Re: Unexpected behaviour of useradd

10 points !vow
I will try

What you can do is first create a user with the required home dir like /home/src

Then add additional users with different home dir's like /home/src1,/home/src2..

What you can do is after creating the users edit the /etc/passwd file and change the home dir of the other users to /home/src.

This will not do a chown.

T G Manikandan
Honored Contributor

Re: Unexpected behaviour of useradd

you can do the same thing using SAM

using the create home dir toggle button.

For the first user enable button.

For the other users disable the toggle button


Thanks
Olivier ROBERT
Frequent Advisor

Re: Unexpected behaviour of useradd

Thanks again for your replies!

Christopher: I could have written my own utilities, but I prefer to restrict myself to the HP interfaces, i.e. useradd or SAM, for consistency purposes, since user management is part of the system's work, and the system is developed by HP. I would not try to execute assembly language in real mode to bypass the system calls. It's in the same spirit that I prefer to use HP interfaces only for creating users, no matter that the interfaces are at a higher level or not.

Cheryl: That's the reply I was waiting for! But I'm surprised about your answer on using SAM, since I thought SAM was using useradd. Btw, I didn't find the reference 5003407825 in the technical knowledge base.

TG: I thought of making useradd with different directories, but with a usermod following. I don't want to edit the password file, since it bypasses the system interfaces. Eventually, I can tolerate using vipw, but I use it only when necessary, since I suspect that its file locking mechanism is not consistent with useradd's and SAM's, though it should be... But after all, maybe it is! Thanks for the effort anyway, and though you don't have the HP logo near such a nice hat, here are the ten points (6+4) :o)

Regards,

Olivier
Cheryl Griffin
Honored Contributor

Re: Unexpected behaviour of useradd

Hoping to get the command used from the SAMlog I went through the steps in SAM, but it did not record it! It simply says "cherylg added". How useful is that?!

There is 1 ER and a number of SR's. If you would like, I can sort through which SR is the still open, and then I can register you in the SR Notify Database so that you are emailed when the issue is addressed.
"Downtime is a Crime."
Martin Johnson
Honored Contributor

Re: Unexpected behaviour of useradd

I got bit by this problem a couple of years ago. A fellow sysadmin set up a pseudo root account for himself on our pop3 mail server. He used useradd and put / as his home directory. He became the owner of every file on the system. Unfortunately, this broke the mail server. He did this just before going home for the day.

It took me a couple of hours to straighten things out. I don't work very well with irate VPs breathing down my neck, asking when they can get their email back.

My coworker now has the nickname of "chown boy".

Marty
Martin Johnson
Honored Contributor

Re: Unexpected behaviour of useradd

I got bit by this problem a couple of years ago. A fellow sysadmin set up a pseudo root account for himself on our pop3 mail server. He used useradd and put / as his home directory. He became the owner of every file on the system. Unfortunately, this broke the mail server. He did this just before going home for the day.

It took me a couple of hours to straighten things out. I don't work very well with irate VPs breathing down my neck, asking when they can get their email back.

My coworker now has the nickname of "chown boy".

Marty
Martin Johnson
Honored Contributor

Re: Unexpected behaviour of useradd

Sorry for the double reply. I didn't get any screen change on my first submit so I assumed it didn't take and tried again.

Marty
Olivier ROBERT
Frequent Advisor

Re: Unexpected behaviour of useradd

Thanks for your continued help,

Cheryl: Eventually, I don't know what ERs and SRs are, but I suppose that "R" means "Report", and that sounds interesting, thanks in advance if you can add me to the notify list about that useradd problem!

Martin: It's good to know that I'm not alone... in some sense! As I can see, I could have been less lucky... I hope I won't get that nickname too!

Regards,

Olivier