Debian Admin - Your way to Debian World

October 11, 2006

Users and Groups Administration in Linux

by @ 6:54 am. Filed under General

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

The user information is stored in the system /etc/passwd and /etc/shadow files, and that additionally, group membership information is stored in the /etc/group file. The update-passwd tool keeps the entries in these master files in sync on all Debian systems.While it is possible to edit these files by hand, it is not recommended.There exist several command line tools, which can be used to manage these files instead.

Now we are going to see the complete users and groups administration commands with examples and man pages.

Users Administration in Linux

Add New User in Linux

useradd - Create a new user or update default new user information

Syntax

useradd [-c comment] [-d home_dir] [-e expire_date] [-f inactive_days] [-g initial_group] [-G group[,…]] [-m [-k skeleton_dir]] [-o] [-p passwd] [-s shell] [-u uid] login

useradd -D [-g default_group] [-b default_home] [-e default_expire_date]
[-f default_inactive] [-s default_shell]

If you want to know more available options you need to check the useradd man page

Examples

Adding New User

First you need to create three (test1,test2,admin1) groups for our examples using groupadd

Options

-d home directory

-s starting program (shell)

-p password

-g (primary group assigned to the users)

-G (Other groups the user belongs to)

-m (Create the user’s home directory )

To add a new user with

a primary group of test1

a second group test2

starting shell /bin/bash

password of xxxx

home directory of admin

create home directory

a login name of admin

#useradd -g test1 -G test2 -s /bin/bash -p xxxx -d/home/admin -m admin

This will create a new user admin.

One additional switch worth mentioning is “-D”, which controls the defaults for useradd.

Specifying the “-D” switch on its own will simply display the default settings, while specifying -D in conjunction with other switches will change the defaults to those values.

# useradd -D

GROUP=100
INACTIVE=-1HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel

# useradd -D -s /bin/sh

# useradd -D

GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/sh
SKEL=/etc/skel

As you can see, this changes the default shell for created users from “bash” to “sh”.

adduser - User Friendly Frontend for useradd command

Syntax

adduser [options] user group

If you want to know available option refer add user man page

Example

#adduser admin

Adding user `admin’ …
Adding new group `admin’ (1001) …
Adding new user `admin’ (1001) with group `admin’ …
Creating home directory `/home/admin’ …
Copying files from `/etc/skel’ …
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for admin
Enter the new value, or press ENTER for the default
Full Name []: Admin
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [y/N] y

You’ll notice that, by default, the adduser command creates a group with the same name as the username, and makes this group the primary group for that user. This is called a user private group (UPG)

Modify User in Linux

usermod - Modify a user account

Syntax

usermod [-c comment] [-d home_dir [-m]] [-e expire_date] [-f inactive_days]
[-g initial_group] [-G group [,…]] [-l login_name] [-p passwd] [-s shell] [-u uid [-o]] [-L|-U] login

If you want to know available option check usermod man page

Example

Options:

-d home directory

-s starting program (shell)

-p password

-g (primary group assigned to the users)

-G (Other groups the user belongs to)

To add the group ‘others’ to the user admin

#usermod -G others admin

Delete User in Linux

userdel - Delete a user account and related files

Syntax

userdel [-r] login

If you want to know available options check userdel man page

Example

Options

-r (remove home directory)

To remove the user ‘admin’ and his home directory

#userdel -r admin

deluser - remove a user from the system

Syntax

deluser [options] user group

If you want more options check deluser man page

Example

By default, deluser will remove the user without removing the home directory, the mail spool or any other files on the system owned by the user. Removing the home directory and mail spool can be achieved using the –remove-home option. If the –home option is given, deluser will only remove the user if the directory given to the –home option matches the user’s real home directory.

#deluser –remove-home admin

Groups Administration in Linux

Add New Group in Linux

groupadd - Create a new group

Syntax

groupadd [-g gid [-o]] group

For more options check groupadd man page

Example

#groupadd test1

This will create a test1 group

addgroup - add a group to the system

Syntax

addgroup [options] [–gid ID] group

If you want to know available options check addgroup man page

#addgroup

Enter a groupname to add: admin1
Adding group `admin1′ (1001)…
Done.

Modify Group in Linux

groupmod - Modify a group

Syntax

groupmod [-g gid [-o]] [-n group_name ] group

For more options check groupmod man page

Example

#groupmod test1 test2

This will modify group name test1 to test2

Delete group in Linux

groupdel - Delete a group

Syntax

groupdel groupname

For more options check groupdel man page

Example

#groupdel test2

this will delete the test2 group

delgroup - remove a group from the system

Syntax

delgroup [options] [–only-if-empty] group

For more details about options check delgroup man page

Example

#delgroup –only-if-empty test2

Removing group `test2′…
done.

groups Command

print the groups a user is in

Syntax

groups [username]

This simple command displays what groups a user is a member of. It takes the username of user as a parameter. If no username is given, it defaults to the current user.

# groups

root

# groups admin

test1 : test2

Tags: , , , , , , , , , ,

You may also be interested in...

Leave a Reply

Subscribe RSS Feed

subscribe to the Debian Admin RSS feed

Internal links:

Sponsors:



Categories:

Support Debian Admin

Amount $:
Website(Optional):

Sponsors:

Archives:

Related Links:


Favourite Sites:

Wordpress Collection
Windows Reference
Ubuntu Geek
DebianHelp
All About Debian Tutorials
Power Electrical
Check Your IP Here
Debian,Ubuntu News
DebCentral
Tuxmachines
Capnkirby
Libervis
Nuxifield
Linux Horizon
Linux Appfinder
Debuntu
GNU/Linux For Everyone
Free Penguin
DebianAdmin is not related to the Debian Project.
This site is copyright © 2006,2007 Debian Admin
All Trademarks are the property of their respective owners.
The contents of this website may not be mirrored or archived without the express written permission of DebianAdmin Site Owner.

DISCLAIMER: All the information, troubleshooting methods, utilities offered in this website is provided AS-IS, without any warranties. Though I strive for perfection, and always test the validity and effectiveness of the troubleshooting content in various systems, I assume no responsibility for your use of these Fixes, Utilities and other troubleshooting advice. The author will not be liable for any special, incidental, consequential or indirect damages due to loss of data or any other reason. All use is completely at your own risk. Changes to the existing content and new additions are made to this website periodically, without notification.
Rodney's Kontera DynamiContext Plugin plugged in.