Saturday, 10 November 2012

Manually creating a user

Sometimes creating the user with "useradd" utility does not properly configure the user account and hence we have to rely on manually creating one, which is quite simple.

For setting up the user manually we have to edit 3 files, copy one folder and we are done.
We are assuming that you have the write access to the fiels and folders, that is you have root access or you can do sudo

Lets say we need to create a user called "jd".
1. edit /etc/passwd
linux-b0yq:~ #vim /etc/passed
enter the following entry
jd is the user login
1000 is the UID
100 is the GID
jd is full name
/home/jd is the home directory
/bin/bash shell to start when the user logs in.

2. edit /etc/shadow
linux-b0yq:~ # vim /etc/shadow
enter the following entry
We are leaving the password field(2nd field) as *, because it takes a hash value which we do not know, so we will rest the password of this user using "passwd"

3. edit /etc/group, where you can add the new user jd to a new group or to the existing group, lets say we add to the new group called dev_group.
linux-b0yq:~ # vim /etc/group
enter the following entry
dev_group is the new group
500 is the GID
jd is the user that belong to this group, you can also add the multiple comma separated users here.

Creating the home directory for the user.

copy the /etc/skel to /home/ and rename it to jd.
linux-b0yq:~ # cp -r /etc/skel /home/
linux-b0yq:~ # mv /home/skel/ /home/jd
Changing the  owner ship of the user's home directory
linux-b0yq:~ # ls -all /home/jd
you will get the output like
rwxr-xr-x 31 root     users  4096 Nov 10 21:05 jd
Note the third field where it says "root", that is the owner of this directory is root, now we have to change the ownership of this folder to jd
linux-b0yq:~ # chown -Rv jd /home/jd
One last this is that we have to set the user jd's password.
linux-b0yq:~ # passwd jd

Enter the password and and reenter the password.

The user jd is good as gold.

No comments:

Post a Comment