Friday, November 9, 2018

Files and Directories Management | RHCSA | linux tutorial

In Linux everything are kept in form of files so accessing and managing them becomes a critical part as Linux user.

Following command is used to create a blank file or update the time stamp of any current file. As you see below we created a new file with name as a1 and than updated its time stamp with touch command itself.
[root@localhost ravi]# touch a1
[root@localhost ravi]# ls -l a1
-rw-r--r-- 1 root root 0 Nov  9 01:57 a1

[root@localhost ravi]# touch a1
[root@localhost ravi]# ls -l a1
-rw-r--r-- 1 root root 0 Nov  9 01:58 a1

Following command is used to copy files and directories in Linux.
[root@localhost ravi]# cp a1 b1
[root@localhost ravi]# ls
a1  b1
[root@localhost ravi]# ls -l
total 8
-rw-r--r-- 1 root root 0 Nov  9 01:58 a1
-rw-r--r-- 1 root root 0 Nov  9 02:03 b1

Following command is used to create the directory in Linux.
[root@localhost ravi]# mkdir dir1
[root@localhost ravi]# ls
a1  b1  dir1
[root@localhost ravi]# cd dir1/
[root@localhost dir1]# ls
[root@localhost dir1]# 

Following command is used to delete the files and folder in Linux. rm command is used to delete both directories and file. rmdir is a specific command to delete the directories. rm with -rf is used to delete files or folder recursively and forcefully. 
[root@localhost ravi]# ls
a1  b1  dir1
[root@localhost ravi]# rmdir dir1/
[root@localhost ravi]# ls
a1  b1
[root@localhost ravi]# rm a1
rm: remove regular empty file `a1'? y
[root@localhost ravi]# rm -rf b1
[root@localhost ravi]# ls
[root@localhost ravi]# 

Following command is used to move or rename the files or directories in Linux.
[root@localhost ravi]# ls -l
total 12
-rw-r--r-- 1 root root    0 Nov  9 02:31 a1
drwxr-xr-x 2 root root 4096 Nov  9 02:32 dir1
[root@localhost ravi]# mv a1 b1
[root@localhost ravi]# ls
b1  dir1
[root@localhost ravi]# mv dir1 dir2
[root@localhost ravi]# ls
b1  dir2


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...