How do I add a user to group under Ubuntu Linux operating system using command line options?
You need to use the following commands:
| Tutorial details | |
|---|---|
| Difficulty | Intermediate (rss) |
| Root privileges | Yes |
| Requirements | useradd / usermod |
[a] useradd command - Create a new user or update default new user information or add a new user to secondary group.
[b] usermod command - Modifies the system account and make changes to existing user accounts.
First, login as the root user
You must login as the root user. You can switch to the root user by typing 'su -' and entering the root password, when prompted. However, sudo command is recommend under Ubuntu Linux for switching to root user:
su -OR
sudo -sOR
sudo useradd ...Ubuntu Linux: add a new user to secondary group
Use the following syntax:
useradd -G Group-name Username
passwd Username
Create a group called foo and add user tom to a secondary group called foo:
$ sudo groupadd foo
$ sudo useradd -G foo tom
OR
# groupadd foo
# useradd -G foo tom
Verify new settings:
id tom groups tom
Finally, set the password for tom user, enter:
$ sudo passwd tom
OR
# passwd tom
You can add user tom to multiple groups - foo, bar, and ftp, enter:
# useradd -G foo,bar,ftp top
Ubuntu Linux: add a new user to primary group
To add a user tom to a group called www use the following command:
useradd -g www tom id tom groups tom
Ubuntu Linux: add a existing user to existing group
To add an existing user jerry to ftp supplementary/secondary group with usermod command using -a option ~ i.e. add the user to the supplemental group(s). Use only with -G option:
usermod -a -G ftp jerry id jerry
To change existing jerry's primary group to www, enter:
usermod -g www jeryy
For more information and options read the following man pages:
man 8 useradd
man 8 usermod
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop







![Linux: Find Out My Group Name [ Group Memberships ]](http://s13.cyberciti.org/images/shared/rp/3/7.jpg)





{ 4 comments… read them below or add one }
For debian based system you can use adduser
#adduser tom group
Hi,
I want to create many users with same permission at Amazon EC2.
How can i do it?
im unable to login tothe new users created using “useradd” command.please help.
# useradd -G foo,bar,ftp top
should be
# useradd -G foo,bar,ftp tom
^
I