4

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.

Flyk
  • 1,480
Sachin
  • 171

2 Answers2

4

Have you tried doing this with adduser instead? The Ubuntu Help page recommends not using useradd. 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 using useradd or usermod.

jpetersen
  • 5,379
  • Actually as I said in the question, the problem is not of adding a new user, that is working fine. The problem is of adding an existing user to the new user's group. I tried adding the old user to the new user created using adduser but the problem persists – Sachin Jun 15 '12 at 06:51
  • 1
    adduser user group adds user to group per adduser(1) – Michael Wild Jun 15 '12 at 07:54
  • Remember you need to log out and back in for new permissions to take effect. This got me! – Chad Nov 24 '17 at 00:34
-1

It is likely that you just need to logout and login again to let the new permission to become effective.

Ben Lin
  • 297
  • 2
  • 3