From 4e0d1ae27ab6a25bd6204566a923892ed1cda684 Mon Sep 17 00:00:00 2001
From: Kalyanasundaram Somasundaram
Using --help to show the documentation for ls command.
-

The linux file system has a hierarchical (or tree-like) structure with its highest level directory called root ( denoted by / ). Directories present inside the root directory stores file related to the system. These directories in turn can either store system files or application files or user related files.
-

bin | The executable program of most commonly used commands reside in bin directory
sbin | This directory contains programs used for system administration.
home | This directory contains user related files and directories.
@@ -1262,25 +1262,25 @@ online bash shell.
At any given moment of time, we will be standing in a certain directory. To get the name of the directory in which we are standing, we can use the pwd command in linux.
-

We will now use the cd command to move to a different directory and then print the working directory.
-

The cd command can be used to change the working directory. Using the command, you can move from one directory to another.
In the below example, we are initially in the root directory. we have then used the cd command to change the directory.
-

The ls command is used to list the contents of a directory. It will list down all the files and folders present in the given directory.
If we just type ls in the shell, it will list all the files and directories present in the current directory.
-

We can also provide the directory name as argument to ls command. It will then list all the files and directories inside the given directory.
-

There are four basic commands which are used frequently to manipulate files:
@@ -1311,14 +1311,14 @@ the simplest use case of creating a new file.General syntax of using touch command
touch <file_name>
-

The mkdir command is used to create directories.You can use ls command to verify that the new directory is created.
General syntax of using mkdir command
mkdir <directory_name>
-

The rm command can be used to delete files and directories. It is very important to note that this command permanently deletes the files and @@ -1331,7 +1331,7 @@ run this command with care.
Let's try to understand the rm command with an example. We will try to delete the file and directory we created using touch and mkdir command respectively.
-

The cp command is used to copy files and directories from one location to another. Do note that the cp command doesn't do any change to the @@ -1344,14 +1344,14 @@ their copy both co-exist after running cp command successfully.
command to create a new directory named "test_directory". We will now try to copy the "_test_runner.py" file to the directory we created just now. -

Do note that nothing happened to the original "_test_runner.py" file. It's still there in the current directory. A new copy of it got created inside the "test_directory".
-

We can also use the cp command to copy the whole directory from one location to another. Let's try to understand this with an example.
-

We again used the mkdir command to create a new directory called "another_directory". We then used the cp command along with an additional argument '-r' to copy the "test_directory".
@@ -1368,7 +1368,7 @@ move the files or directories, the original copy is lost. already exists in "test_directory". The mv command will just replace it. Do note that the original file doesn't exist in the current directory after mv command ran successfully. -

We can also use the mv command to move a directory from one location to another. In this case, we do not need to use the '-r' flag that we did while using the cp command. Do note that the original directory will not @@ -1377,7 +1377,7 @@ exist if we use mv command.
directories. Let's see how we can use this command for renaming.We have first changed our location to "test_directory". We then use the mv command to rename the ""_test_runner.py" file to "test.py".
-

There are three basic commands which are used frequently to view the files:
@@ -1397,7 +1397,7 @@ these commands. You should also practice the given examples on the online bash shell.We will create a new file called "numbers.txt" and insert numbers from 1 to 100 in this file. Each number will be in a separate line.
-

Do not worry about the above command now. It's an advanced command which is used to generate numbers. We have then used a redirection operator to push these numbers to the file. We will be discussing I/O redirection in the @@ -1406,7 +1406,7 @@ later sections.
The most simplest use of cat command is to print the contents of the file on your output screen. This command is very useful and can be used for many other purposes. We will study about other use cases later.
-

You can try to run the above command and you will see numbers being printed from 1 to 100 on your screen. You will need to scroll up to view all the numbers.
@@ -1416,20 +1416,20 @@ can include additional arguments to display as many lines as we want from the top.In this example, we are only able to see the first 10 lines from the file when we use the head command.
-

By default, head command will only display the first 10 lines. If we want to specify the number of lines we want to see from start, use the '-n' argument to provide the input.
-

The tail command displays the last 10 lines of the file by default. We can include additional arguments to display as many lines as we want from the end of the file.
-

By default, the tail command will only display the last 10 lines. If we want to specify the number of lines we want to see from the end, use '-n' argument to provide the input.
-

In this example, we are only able to see the last 5 lines from the file when we use the tail command with explicit -n option.
The echo command prints the given input string on the screen.
-

In the previous section, we learned how to view the content of a file. In many cases, we will be interested in performing the below operations:
@@ -1470,7 +1470,7 @@ these commands. You should also practice the given examples on the online bash shell.We will create a new file called "numbers.txt" and insert numbers from 1 to 10 in this file. Each number will be in a separate line.
-

The grep command in its simplest form can be used to search particular words in a text file. It will display all the lines in a file that @@ -1481,7 +1481,7 @@ an input to the grep command.
In this example, we are trying to search for a string "1" in this file. The grep command outputs the lines where it found this string.
-

The sed command in its simplest form can be used to replace a text in a file.
@@ -1490,7 +1490,7 @@ file.Let's try to replace each occurrence of "1" in the file with "3" using sed command.
-

The content of the file will not change in the above example. To do so, we have to use an extra argument '-i' so that the changes are reflected back in the file.
@@ -1498,10 +1498,10 @@ changes are reflected back in the file.The sort command can be used to sort the input provided to it as an argument. By default, it will sort in increasing order.
Let's first see the content of the file before trying to sort it.
-

Now, we will try to sort the file using the sort command. The sort command sorts the content in lexicographical order.
-

The content of the file will not change in the above example.
In the below example, we have used the '>' operator to redirect the output of ls command to output.txt file.
-

In the below example, we have redirected the output from echo command to a file.
-

We can also redirect the output of a command as an input to another command. This is possible with the help of pipes.
In the below example, we have passed the output of cat command as an input to grep command using pipe(|) operator.
-

In the below example, we have passed the output of sort command as an input to uniq command using pipe(|) operator. The uniq command only prints the unique numbers from the input.
-

I/O redirection - https://tldp.org/LDP/abs/html/io-redirection.html


The Linux kernel is monolithic in nature.
diff --git a/linux_basics/linux_server_administration/index.html b/linux_basics/linux_server_administration/index.html index 2ca5e51..2b8b932 100644 --- a/linux_basics/linux_server_administration/index.html +++ b/linux_basics/linux_server_administration/index.html @@ -1454,7 +1454,7 @@ commands on your own.We will be running all the commands on Red Hat Enterprise Linux (RHEL) 8 system.


id command can be used to find the uid and gid associated with an user. It also lists down the groups to which the user belongs to.
The uid and gid associated with the root user is 0.
-
A good way to find out the current user in linux is to use the whoami command.
-

"root" user or superuser is the most privileged user with unrestricted access to all the resources on the system. It has UID 0






If you want to understand each filed discussed in the above outputs, you can go through below links:


If we do not specify any value for attributes like home directory or login shell, default values will be assigned to the user. We can also override these default values when creating a new user.
-

The passwd command is used to create or modify passwords for a user.
In the above examples, we have not assigned any password for users 'shivam' or 'amit' while creating them.
\"!!\" in an account entry in shadow means the account of an user has been created, but not yet given a password.
-

Let's now try to create a password for user "shivam".
-

Do remember the password as we will be later using examples where it will be useful.
Also, let's change the password for the root user now. When we switch from a normal user to root user, it will request you for a password. Also, when you login using root user, the password will be asked.
-

The usermod command is used to modify the attributes of an user like the home directory or the shell.
Let's try to modify the login shell of user "amit" to "/bin/bash".
-

In a similar way, you can also modify many other attributes for a user. Try 'usermod -h' for a list of attributes you can modify.
Let's try to delete the user "amit". After deleting the user, you will not find the entry for that user in "/etc/passwd" or "/etc/shadow" file.
-

Commands for managing groups are quite similar to the commands used for managing users. Each command is not explained in detail here as they are quite similar. You can try running these commands on your system.


We will now try to add user "shivam" to the group we have created above.
-

Before running the below commands, do make sure that you have set up a password for user "shivam" and user "root" using the passwd command described in the above section.
The su command can be used to switch users in linux. Let's now try to switch to user "shivam".
-

Let's now try to open the "/etc/shadow" file.
-

The operating system didn't allow the user "shivam" to read the content of the "/etc/shadow" file. This is an important file in linux which stores the passwords of users. This file can only be accessed by root or @@ -1627,30 +1627,30 @@ need to be a part of the sudo group.
How to provide superpriveleges to other users ?
Let's first switch to the root user using su command. Do note that using the below command will need you to enter the password for the root user.
-

In case, you forgot to set a password for the root user, type "exit" and you will be back as the root user. Now, set up a password using the passwd command.
The file /etc/sudoers holds the names of users permitted to invoke sudo. In redhat operating systems, this file is not present by default. We will need to install sudo.
-

We will discuss the yum command in detail in later sections.
Try to open the "/etc/sudoers" file on the system. The file has a lot of information. This file stores the rules that users must follow when running the sudo command. For example, root is allowed to run any commands from anywhere.
-

One easy way of providing root access to users is to add them to a group which has permissions to run all the commands. "wheel" is a group in redhat linux with such privileges.
-

Let's add the user "shivam" to this group so that it also has sudo privileges.
-

Let's now switch back to user "shivam" and try to access the "/etc/shadow" file.
-

We need to use sudo before running the command since it can only be accessed with the sudo privileges. We have already given sudo privileges to user “shivam” by adding him to the group “wheel”.
@@ -1661,11 +1661,11 @@ users and everybody else. This is to make sure that one user is not allowed to access the files and resources of another user.To see the permissions of a file, we can use the ls command. Let's look at the permissions of /etc/passwd file.
-

Let's go over some of the important fields in the output that are related to file permissions.
-



The chmod command is used to modify files and directories permissions in linux.
@@ -1733,30 +1733,30 @@ allowed and 0 representing False or not allowed.We will now create a new file and check the permission of the file.
-

The group owner doesn't have the permission to write to this file. Let's give the group owner or root the permission to write to it using chmod command.
-

Chmod command can be also used to change the permissions of a directory in the similar way.
The chown command is used to change the owner of files or directories in linux.
Command syntax: chown \<new_owner> \<file_name>
-

In case, we do not have sudo privileges, we need to use sudo command. Let's switch to user 'shivam' and try changing the owner. We have also changed the owner of the file to root before running the below command.
-

Chown command can also be used to change the owner of a directory in the similar way.
The chgrp command can be used to change the group ownership of files or directories in linux. The syntax is very similar to that of chown command.
-

Chgrp command can also be used to change the owner of a directory in the similar way.
Generating public-private key pair
If we already have a key pair stored in \~/.ssh directory, we will not need to generate keys again.
Install openssh package which contains all the commands related to ssh.
-

Generate a key pair using the ssh-keygen command. One can choose the default values for all prompts.
-

After running the ssh-keygen command successfully, we should see two keys present in the \~/.ssh directory. Id_rsa is the private key and id_rsa.pub is the public key. Do note that the private key can only be read and modified by you.
-

Transferring the public key to the remote host
There are multiple ways to transfer the public key to the remote server. We will look at one of the most common ways of doing it using the ssh-id-copy command.
-

Install the openssh-clients package to use ssh-id-copy command.
-

Use the ssh-id-copy command to copy your public key to the remote host.
-

Now, ssh into the remote host using the password authentication.
-

Our public key should be there in \~/.ssh/authorized_keys now.
-

\~/.ssh/authorized_key contains a list of public keys. The users associated with these public keys have the ssh access into the remote host.
@@ -1809,10 +1809,10 @@ host.General syntax: ssh \<user>@\<hostname/hostip> \<command>
-

General syntax: scp \<source> \<destination>
-

Package management is the process of installing and managing software on the system. We can install the packages which we require from the linux @@ -1867,38 +1867,38 @@ systems.
the successor to YUM which is now used in Fedora for installing and managing packages. DNF may replace YUM in the future on all RPM based linux distributions. -

We did find an exact match for the keyword httpd when we searched using yum search command. Let's now install the httpd package.
-

After httpd is installed, we will use the yum remove command to remove httpd package.
-

In this section, we will study about some useful commands that can be used to monitor the processes on linux systems.
The ps command is used to know the information of a process or list of processes.
-

If you get an error "ps command not found" while running ps command, do install procps package.
ps without any arguments is not very useful. Let's try to list all the processes on the system by using the below command.
Reference: https://unix.stackexchange.com/questions/106847/what-does-aux-mean-in-ps-aux
-

We can use an additional argument with ps command to list the information about the process with a specific process ID.
-

We can use grep in combination with ps command to list only specific processes.
-

The top command is used to show information about linux processes running on the system in real time. It also shows a summary of the system information.
-

For each process, top lists down the process ID, owner, priority, state, cpu utilization, memory utilization and much more information. It also lists down the memory utilization and cpu utilization of the system as a @@ -1910,28 +1910,28 @@ used to view information about the system memory.
The free command is used to display the memory usage of the system. The command displays the total free and used space available in the RAM along with space occupied by the caches/buffers.
-

free command by default shows the memory usage in kilobytes. We can use an additional argument to get the data in human-readable format.
-

The vmstat command can be used to display the memory usage along with additional information about io and cpu usage.
-

In this section, we will study about some useful commands that can be used to view disk space on linux.
The df command is used to display the free and available space for each mounted file system.
-

The du command is used to display disk usage of files and directories on the system.
-

The below command can be used to display the top 5 largest directories in the root directory.
-

A computer program that runs as a background process is called a daemon. Traditionally, the name of daemon processes ended with d - sshd, httpd @@ -1946,7 +1946,7 @@ represented by unit configuration files.
/usr/lib/systemd/system which are distributed by installed RPM packages. We are more interested in the configuration file that ends with service as these are service units. -

Service units end with .service file extension. Systemctl command can be used to start/stop/restart the services managed by systemd.
@@ -1985,7 +1985,7 @@ used to start/stop/restart the services managed by systemd. which can be very useful for viewing system logs and applications logs in linux. These logs can be very useful when you are troubleshooting on the system. -
