I am having this strange problem. I am using usermod
to add an existing user to another group. I want to create a new user and add an old user to this new user's group. To do this, I am doing the following things
Create a new user, -m creates the home directory for the user and -U creates a group by the same name, as that of the user.
useradd -U -m newuser
Then I add the old user to the new user's group as
usermod -a -G newuser olduser
-a
appends this group to the already existing groups and -G
is used to give the group name.
Now when I do groups olduser
I get the following out put olduser newuser
, but being the olduser
I am unable to create a any file in the newuser
home directory. I have set the proper directory permissions, the read, write and execute bit is set for group.
However if, instead of using usermod
I manually edit the /etc/group
file, and add newuser,olduser
in front of the newuser group then everything works correctly. Is there a bug in usermod
or I am doing something wrong.
Best Answer
Have you tried doing this with
adduser
instead? The Ubuntu Help page recommends not usinguseradd
. I think what your trying to do could be done like this:adduser newuser
(automatically makes home folder)adduser newuser olduser
(this adds newuser to the olduser group)Hope that helps.
EDIT:
This should at least help you figure out if the problem is related to
usermod
or not. Try to add the user and change groups without usinguseradd
orusermod
.