Thursday, April 12, 2018

Linux Tutorial | User Management | Create Delete Manage User

Linux is a multi-user system so it has the ability in which single user can have multiple sessions at same time and multiple users can have sessions at single time. Due to which user management play's a big part as Linux is all about permissions and tasks which users can perform. We will see here how to manage users and assign them specific groups.

To create a user in Linux system we have two commands:
[root@ip-10-0-1-25 ec2-user]# which adduser
/usr/sbin/adduser

[root@ip-10-0-1-25 ec2-user]# which useradd
/usr/sbin/useradd

 To check the parameters on which user will be created we can see via following command:
[root@ip-10-0-1-25 ec2-user]# adduser -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

[root@ip-10-0-1-25 ec2-user]# useradd -D
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes

To create a simple user:
[root@ip-10-0-1-25 ec2-user]# useradd ravi

[root@ip-10-0-1-25 ec2-user]# id ravi
uid=502(ravi) gid=502(ravi) groups=502(ravi)

id command : Its used to see the details of the any user.

Lets check the details of user we have created:
[root@ip-10-0-1-25 ec2-user]# grep ravi /etc/passwd
ravi:x:502:502::/home/ravi:/bin/bash

Following is the breakup of /etc/passwd entries:
[Username]:[Shadowed Password Protected]:[UID]:[GID]:[Comment]:[Home directory]:[Default shell]

Lets check the details of default group created for user:
[root@ip-10-0-1-25 ec2-user]# grep ravi /etc/group
ravi:x:502:

Following is the breakup of /etc/group entries:
[Group name]:[Group password]:[GID]:[Group members]

Now look at the default files which will be created for user in his home directory. The files are copied from /etc/skel to home directory of user. These files are used to setup working environment for user including system variables and user specific system variables.

[root@ip-10-0-1-25 ec2-user]# ls -a /home/ravi/
.  ..  .bash_logout  .bash_profile  .bashrc

[root@ip-10-0-1-25 ec2-user]# ls -a /etc/skel/
.  ..  .bash_logout  .bash_profile  .bashrc


To set password for user via root user:
[root@ip-10-0-1-25 ec2-user]# passwd ravi
Changing password for user ravi.
New password: 
Retype new password: 
passwd: all authentication tokens updated successfully.


Create user with custom UID:
[root@ip-10-0-1-25 ec2-user]# useradd -u "510" ravi1

[root@ip-10-0-1-25 ec2-user]# id ravi1
uid=510(ravi1) gid=510(ravi1) groups=510(ravi1)

Create user with primary group of another user:
[root@ip-10-0-1-25 ec2-user]# useradd -g "ravi" ravi2

[root@ip-10-0-1-25 ec2-user]# id ravi2
uid=511(ravi2) gid=502(ravi) groups=502(ravi)

Create user with secondary group of another user:
[root@ip-10-0-1-25 ec2-user]# useradd -G "ravi" ravi3

[root@ip-10-0-1-25 ec2-user]# id ravi3
uid=512(ravi3) gid=512(ravi3) groups=512(ravi3),502(ravi)

Create user with custom home directory:
[root@ip-10-0-1-25 ec2-user]# useradd -d /home/test ravi4

[root@ip-10-0-1-25 ec2-user]# grep ravi4 /etc/passwd
ravi4:x:513:513::/home/test:/bin/bash

Create user with comment:
[root@ip-10-0-1-25 ec2-user]# useradd -c "Ravi Gadgil" ravi5

[root@ip-10-0-1-25 ec2-user]# grep ravi5 /etc/passwd
ravi5:x:514:514:Ravi Gadgil:/home/ravi5:/bin/bash

Lock user access:
[root@ip-10-0-1-25 ec2-user]# usermod --lock ravi5
[root@ip-10-0-1-25 ec2-user]# su ravi
[ravi@ip-10-0-1-25 ec2-user]$ su ravi5
Password: 
su: Authentication failure

Unlock user access:
[root@ip-10-0-1-25 ec2-user]# usermod --unlock ravi5
[root@ip-10-0-1-25 ec2-user]# su ravi
[ravi@ip-10-0-1-25 ec2-user]$ su ravi5
Password: 
[ravi5@ip-10-0-1-25 ec2-user]$ 

Delete a user:
[root@ip-10-0-1-25 ec2-user]# userdel ravi5

[root@ip-10-0-1-25 ec2-user]# id ravi5
id: ravi5: no such user

Delete a user with his home directory:
[root@ip-10-0-1-25 ec2-user]# userdel -r ravi4

[root@ip-10-0-1-25 ec2-user]# id ravi4
id: ravi4: no such user

[root@ip-10-0-1-25 ec2-user]# ls /home/
ravi  ravi1  ravi2  ravi3  ravi5

Setup fully configurable EFK Elasticsearch Fluentd Kibana setup in Kubernetes

In the following setup, we will be creating a fully configurable Elasticsearch, Flunetd, Kibana setup better known as EKF setup. There is a...