Welcome to UltratechHost Forum, Guest. Please take the time to register if you haven't, or click

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

[-]
Tags
guide to “useradd” command in linux part 1

RedHat Guide to “useradd” Command in Linux [Part 1]
#1
Hi,

In this thread we will be know how to add user in a Linux OS, Prior to that we need to be cleared that useradd/adduser command can only be executed using root previlages.

It has many options and they are:
--base-dir
--comment
--create-home
--defaults
--expiredate
--gid
--groups
--help
--home-dir
--inactive
--key
--no-create-home
--no-log-init
--non-unique
--no-user-group
--password
--root
--selinux-user
--shell
--skel
--system
--uid
--user-group

To add a new user called ‘dinesh‘, use the following command:
Code:
#useradd dinesh

When a user is added and we need to assign a password then we need to execute the command as:
Code:
#passwd dinesh
Changing password for user dinesh.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.

Once a new user created, it’s entry automatically added to the ‘/etc/passwd‘ file. The file is used to store users information and the entry should be.

Code:
dinesh:x:505:505:dinesh:/home/dinesh:/bin/bash

The above entry contains a set of seven colon-separated fields, each field has it’s own meaning. Let’s see what are these fields:

  • Username: User login name used to login into system. It should be between 1 to 32 charcters long.


  • Password: User password (or x character) stored in /etc/shadow file in encrypted format.

  • User ID (UID): Every user must have a User ID (UID) User Identification Number. By default UID 0 is reserved for root user and UID’s ranging from 1-99 are reserved for other predefined accounts. Further UID’s ranging from 100-999 are reserved for system accounts and groups.

  • Group ID (GID): The primary Group ID (GID) Group Identification Number stored in /etc/group file.

  • User Info: This field is optional and allow you to define extra information about the user. For example, user full name. This field is filled by ‘finger’ command.

  • Home Directory: The absolute location of user’s home directory.

  • Shell: The absolute location of a user’s shell i.e. /bin/bash.

So the in general /etc/passwd content stored as follows:

Code:
username:password(as x):uid:gid:userinfo:user's home directory:Shell(Absolute Location of a user)

Create a User with Different Home Directory
By default ‘useradd‘ command creates a user’s home directory under /home directory with username. If we want to add the user to a different directory then command will be:

Code:
# useradd -d /data/logs harry

You can see the user home directory and other user related information like user id, group id, shell and comments.

Code:
#cat /etc/passwd | grep harry
#harry:x:505:505::/data/logs:/bin/bash

Create a User with Specific User ID
In Linux, every user has its own UID (Unique Identification Number). By default, whenever we create a new user accounts in Linux, it assigns userid 500, 501, 502 and so on…

But, we can create user’s with custom userid with ‘-u‘ option. For example, the following command will create a user ‘suraj‘ with custom userid ‘891‘.

Code:
# useradd -u 891 suraj

Now, let’s verify that the user created with a defined userid (891) using following command.

Code:
# cat /etc/passwd | grep suraj

suraj:x:891:891::/home/suraj:/bin/bash



Dinesh Kumar Mohanty
Ultra Web Solutions®
Bhubaneswar, Odisha, India.

UltratechHost - Your One Stop Offshore & Onshore Hosting Provider
Server Locations : Netherlands, Germany, Russia, Singapore & USA
Service Offers: Shared hosting | Reseller hosting | Cloud server | Dedicated server | VPS Hosting



Forum Jump:


Users browsing this thread: 1 Guest(s)