Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have an user john and an user keith in Ubuntu server

I added these users using

sudo adduser John 
sudo adduser Keith

How can I now add john to Keith's group?

I tried:

sudo usermod -aG Keith john

But I get:

usermod: group 'Keith' does not exist

What do I need to do to resolve this issue?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

You can use: usermod -a -G grouptoadd username

Since it is far less obvious than I thought why -a -G is ok while -aG is not I'll try to explain it:

The -G options takes either one value or a list of values. In case of one value the value may be given like: -GVALUE since there is no requirement to have a space between the option and the value. This is just common practice.

If you have a group called a on your system, then calling -Ga becomes ambiguous. Do you want the user to have only one group a? Are you calling -a and -G? Then is "a" a value to -G? Where is the rest of the value (to -G)? It is also common practice that any single-letter option can before any other single letter option. so tat -xy == -yz. But this is ambiguous when one of the options can take either a single value like VALUE or many values like VAL1,Val2,val4,etc.

So in order to make the command FAILSAFE and work properly for all input you have to separate -a from -G

From man usermod:

Name

usermod - modify a user account

Synopsis

usermod [options] LOGIN

Description

The usermod command modifies the system account files to reflect the changes that are specified on the command line.

Options

The options which apply to the usermod command are:

  • -a, --append

    Add the user to the supplementary group(s). Use only with the -G option.

  • ...

  • -G, --groups GROUP1[,GROUP2,...[,GROUPN]]]

    A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option.

    If the user is currently a member of a group which is not listed, the user will be removed from the group. This behaviour can be changed via the -a option, which appends the user to the current supplementary group list.

  • ...

share|improve this answer
    
Might help to explain why splitting the options would work, and what options they are. –  Journeyman Geek Oct 13 '12 at 14:35
    
@JourneymanGeek: Done! runs... –  Tom Wijsman Oct 13 '12 at 14:39
    
superusers should know how to man, imho... –  Ярослав Рахматуллин Oct 13 '12 at 14:40
    
@ЯрославРахматуллин, superusers should indeed. However, most questions are asked by "non-superusers" and answered by "superusers". Someone who is new to linux has no reason to know of the man command. In any case, the command you gave is the same as the one executed by the OP, your answer does not explain why it did not work for her. On my system at least, splitting the options makes no difference. –  terdon Oct 13 '12 at 14:51
    
Well, first of all you can't run sudo adduser name sudo adduser name2 because that is invalid syntax for useradd. useradd takes one username argument. To add two users you have to run the command twice. IE useradd arne; useradd kari. Then you can add kari to arnes group and vice versa. Ill grow some more patience after watching a few more of these questions and answer properly. promise! –  Ярослав Рахматуллин Oct 13 '12 at 14:59

You can also edit the configuration files manually:

nano /etc/password

nano /etc/group

Assign the ID and other fields.

share|improve this answer

If you executed the commands exactly as you have shown in your question, you did not create the user Keith, but only the user John. To execute commands one after the other on the command line you need to separate them using ; or &&. Otherwise, only the first command will be run:

sudo adduser John sudo adduser Keith
adduser: Only one or two names allowed.

If you did execute them correctly, be careful about capital letters. In your question you mention both "John" and "john". This should work:

sudo adduser keith
sudo adduser john
sudo usermod -aG keith john
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.