Showing posts with label useradd. Show all posts
Showing posts with label useradd. Show all posts

Thursday, July 28, 2016

how to create a user without useradd command in linux?

Follow these steps to create a user without using useradd command in Red Hat Linux.

Step 1
Add an entry of user details in /etc/passwd

The field details are as shown below
username:password:UID:GID:Comments:Home_Directory:Login Shell

# vi /etc/passwd
user:x:501:501:test user:/home/user:/bin/bash

Step 2
You will have to create a group with same name. So add a new entry in /etc/group
# vi /etc/group

Step 3
Assign a password to the user
# passwd user
Changing password for user user.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

Now let us try to login with our newly created user
# su - user

You should see []$ instead of -bash-4.1$ prompt. So why does this happens?

Let us check the contents of its home directory
-bash-4.1$ ls -al
drwxr-xr-x 2 root root 4096 Jan 16 14:27 .
drwxr-xr-x. 3 root root 4096 Jan 16 14:27 ..

So, as you see none of the default contents of a normal user home directory is present like .bashrc, .bash_profile etc.

Final Step 4

NOTE: /etc/skel directory contains all the defaults files which are present inside the home folder of any user

So, copy the contents from /etc/skel inside /home/user using the below command

[ ~]# cp -v /etc/skel/.* /home/user/
cp: omitting directory `/etc/skel/.'
cp: omitting directory `/etc/skel/..'
`/etc/skel/.bash_logout' -> `/home/user/.bash_logout'
`/etc/skel/.bash_profile' -> `/home/user/.bash_profile'
`/etc/skel/.bashrc' -> `/home/user/.bashrc'
`/etc/skel/.emacs' -> `/home/user/.emacs'
cp: omitting directory `/etc/skel/.gnome2'
cp: omitting directory `/etc/skel/.mozilla'

Now re login to the user
[ ]# su - user

And you are good to go.

NOTE: Do not manually edit /etc/shadow file because it contains the encrypted password section which is automatically generated

# cat /etc/shadow | grep user


Tuesday, January 20, 2015

How to add user in Linux

This is a small “how-to” on adding users in Linux. As Linux is multi-user supporting operating system so that multiple users can login symeltiniously login and do their job. Linux administrators some time require to create user accounts for a project so that the users can login to the machine and work on it. This can be accomplished by executing adduser linux command from terminal. This command will create user accounts with normal privileged access and with default settings such as home directories, type of the shell, UID and GID as well. Only root user can execute adduser command. If a normal user want to create accounts in the system he should be granted access by root user for sudo access for adduser command.

Step1: Add user account with following command

adduser user-name
useradd user-name


adduser rajesh
useradd rajesh

Note: There is one more command useradd which will work similarly as adduser command.

Step2: Set password for this user so that he can login to the machine. If this step is missed user can not login to this machine.

passwd username


passwd rajesh
passwd ******
confirm passwd ******

Step3: Check if the user account is created successfully or not

grep rajesh /etc/passwd
tail /etc/passwd
This command should show you a line contain about user:rajesh details.