Thursday, 14 January 2016

Step by Step How to create user in Linux

Step 1: Create new user with all default option

[root@localhost ~]# useradd sirat
[root@localhost ~]# ls -l /home/
total 0
drwx------. 3 sirat sirat 74 Jan 14 16:05 sirat
[root@localhost ~]# tail -2 /etc/passwd
tcpdump:x:72:72::/:/sbin/nologin
sirat:x:1000:1000::/home/sirat:/bin/bash

[root@localhost ~]#

Step 2: Create new user with user defined home directory

[root@localhost ~]# useradd -d /root/sirat sirat
[root@localhost ~]# tail -1 /etc/passwd
sirat:x:1000:1000::/root/sirat:/bin/bash
[root@localhost ~]# 

Step 3: Create new user with specific user id 

[root@localhost ~]# useradd -u 1500 sirat
[root@localhost ~]# tail -1 /etc/passwd
sirat:x:1500:1500::/home/sirat:/bin/bash

Step 4: Create new user with specific group and  user id 

[root@localhost ~]# useradd -u 1500 -g 10 sirat
[root@localhost ~]# tail -1 /etc/passwd
sirat:x:1500:10::/home/sirat:/bin/bash
 
Note : Here User ID is 1500 and Group ID 10 

Step 5: Create new user in multiple group 

[root@localhost ~]# useradd  -g 10 -G 11,12,tty sirat
[root@localhost ~]# tail -1 /etc/passwd
sirat:x:1000:10::/home/sirat:/bin/bash
[root@localhost ~]# id sirat
uid=1000(sirat) gid=10(wheel) groups=10(wheel),5(tty),11(cdrom),12(mail)
[root@localhost ~]# 

Note: Here wheel is primary group and rest of three (tty, cdrom, mail) are supplementary group

Step 6: Create new user without home directory 

[root@localhost ~]# useradd -M sirat 
[root@localhost ~]# tail -1 /etc/passwd
sirat:x:1000:1000::/home/sirat:/bin/bash
[root@localhost ~]# ls /home/sirat
ls: cannot access /home/sirat: No such file or directory
[root@localhost ~]# 

Step 7: Create new user with custom comment

[root@localhost ~]# useradd -c "Siratun Jannat" sirat
[root@localhost ~]# tail -1 /etc/passwd
sirat:x:1000:1000:Siratun Jannat:/home/sirat:/bin/bash

Step 8: Create new user with custom shell

[root@localhost ~]# useradd -s /sbin/nologin sirat
[root@localhost ~]# tail -1 /etc/passwd
sirat:x:1000:1000::/home/sirat:/sbin/nologin
[root@localhost ~]# 

[root@localhost ~]# cat /etc/default/useradd 
# useradd defaults file
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

Note: Here default shell is "/bin/bash"




No comments:

Post a Comment