create-modify-delete-users-in-linux-unix

4

Click here to load reader

Upload: abclearnn

Post on 13-Apr-2017

27 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Create-Modify-Delete-users-in-Linux-Unix

Create-Modify-Delete-users-in-Linux-Unix

One of the day to day activity for any Linux/UNIX admin is to create new user and modify their attributes as per the end user requirements.

Below is the list of Linux commands that we use for user administration.

useradd ---- For adding a new userusermod---- For modifying user attributesuserdel------ For removing user from Linux machine.

We focus here on useradd command with examples for adding a user in linux.

Note:

For add/modify/remove users, we should have root level privileges or someone having sudo root user credentials.

A non-root user, should raise request or ticket following ITIL standards, for any changes in user credentials on the machine.

Create a new user:

In general, Non root users won't have credentails to create a new user. Instead they have to request the Linux team following ITIL standards to create a new user.

Command Syntax:

Below given are some of the most commonly used options with useradd commands. for more options, please refer to man pages or info of command.

#useradd u -g -G -c -d <user’s working directory> -m –s

Options:

g--------Primary groupG------ Secondary groupC------- Comment at type of userm------make directorys--------Shelld--------Path of user’s home directory.

Page 2: Create-Modify-Delete-users-in-Linux-Unix

Note:

u -----user id’s in RHEL 6 0- 499 are reserved0-99 are system users100-499 are daemon users

500-2147483647 are minimum user id and maximum user ids available to be assigned by linux administrators.

For example,

Create a new user named "john" for database admin team, assigning Bash shell.

Before creating any new user, we should gather few details from end user,

Userid =501 Primary group = dbaSecondry group = salesComment = system adminDirectory = /home/johnShell=/bin/bashUsername = john

Syntax

[root@sys2 ~]# useradd -u 501 -g dba -G sales -c systemadmin -d /home/john -m -s /bin/bash john

Note:

∑ username & user id both are not same. username is generic name for human understanding, whereas userid is unique number assigned to each user by OS for its reference.

∑ In Linux, we can create usernames with capital letters also, but best practice is to follow lower cases.

To check whether a user is created or not, we can use any one of the below ways,

∑ Using "id" command,

[root@sys1 ~]# id johnuid=501(john) gid=501(john) groups=501(john)

Page 3: Create-Modify-Delete-users-in-Linux-Unix

∑ Checking from /etc/passwd file,

[root@sys2 ~]# grep john /etc/passwdjohn:x:501:502:systemadmin:/home/john:/bin/bash

Note:

∑ usernames are case sensitive in Linux and UNIX Flavors. Type, id JOHN and see the output.

∑ If the group doesn’t exist already, then they are created by default with the user name.

Default attributes for new user:

The default attributes for a normal user are user id and group id given by the system.

Default working directory is ‘/home/’

The default shell is bash shell.

For example,

Creating a user in linux machine with default attributes.

The syntax is, #useradd <sampleusername>

[root@sys2 ~]# useradd steve

Checking the details in /etc/passwd file,

[root@sys2 ~]# grep steve /etc/passwd[root@sys2 ~]# grep steve /etc/passwdsteve:x:503:503::/home/steve:/bin/bash

Topic review through questions:

1. How to create a new user in Linux machine?

2. what is the userid value of a user? detail about reserved userid values?