mirror of
https://github.com/linkedin/school-of-sre
synced 2026-01-19 23:18:02 +00:00
docs (level 101): fix typos, punctuation, formatting (#160)
* docs: formatted for readability * docs: rephrased and added punctuation * docs: fix typos, punctuation, formatting * docs: fix typo and format * docs: fix caps and formatting * docs: fix punctuation and formatting * docs: capitalized SQL commands, fixed puntuation, formatting * docs: fix punctuation * docs: fix punctuation and formatting * docs: fix caps,punctuation and formatting * docs: fix links, punctuation, formatting * docs: fix code block formatting * docs: fix punctuation, indentation and formatting
This commit is contained in:
@@ -2,60 +2,52 @@
|
||||
|
||||
## Lab Environment Setup
|
||||
|
||||
One can use an online bash interpreter to run all the commands that are provided as examples in this course. This will also help you in getting a hands-on experience of various linux commands.
|
||||
One can use an online Bash interpreter to run all the commands that are provided as examples in this course. This will also help you in getting a hands-on experience of various Linux commands.
|
||||
|
||||
[REPL](https://repl.it/languages/bash) is one of the popular online bash interpreters for running linux commands. We will be using it for running all the commands mentioned in this course.
|
||||
[REPL](https://repl.it/languages/bash) is one of the popular online Bash interpreters for running Linux commands. We will be using it for running all the commands mentioned in this course.
|
||||
|
||||
## What is a Command
|
||||
|
||||
A command is a program that tells the operating system to perform
|
||||
specific work. Programs are stored as files in linux. Therefore, a
|
||||
specific work. Programs are stored as files in Linux. Therefore, a
|
||||
command is also a file which is stored somewhere on the disk.
|
||||
|
||||
Commands may also take additional arguments as input from the user.
|
||||
These arguments are called command line arguments. Knowing how to use
|
||||
the commands is important and there are many ways to get help in Linux,
|
||||
especially for commands. Almost every command will have some form of
|
||||
documentation, most commands will have a command-line argument -h or
|
||||
\--help that will display a reasonable amount of documentation. But the
|
||||
most popular documentation system in Linux is called man pages - short
|
||||
documentation, most commands will have a command-line argument `-h` or
|
||||
`--help` that will display a reasonable amount of documentation. But the
|
||||
most popular documentation system in Linux is called `man` pages—short
|
||||
for manual pages.
|
||||
|
||||
Using \--help to show the documentation for ls command.
|
||||
Using `--help` to show the documentation for `ls` command.
|
||||
|
||||

|
||||
|
||||
## File System Organization
|
||||
|
||||
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.
|
||||
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 files related to the system.
|
||||
These directories in turn can either store system files or application
|
||||
files or user related files.
|
||||
files or user-related files.
|
||||
|
||||

|
||||
|
||||
bin | The executable program of most commonly used commands reside in bin directory
|
||||
|
||||
dev | This directory contains files related to devices on the system
|
||||
|
||||
etc | This directory contains all the system configuration files
|
||||
|
||||
home | This directory contains user related files and directories.
|
||||
|
||||
lib | This directory contains all the library files
|
||||
|
||||
mnt | This directory contains files related to mounted devices on the system
|
||||
|
||||
proc | This directory contains files related to the running processes on the system
|
||||
|
||||
root | This directory contains root user related files and directories.
|
||||
|
||||
sbin | This directory contains programs used for system administration.
|
||||
|
||||
tmp | This directory is used to store temporary files on the system
|
||||
|
||||
usr | This directory is used to store application programs on the system
|
||||
| Directory | Description |
|
||||
|------------|--------------------------------------------------------------------------------|
|
||||
| bin | The executable program of most commonly used commands reside in `bin` directory|
|
||||
| dev | This directory contains files related to devices on the system |
|
||||
| etc | This directory contains all the system configuration files |
|
||||
| home | This directory contains user-related files and directories |
|
||||
| lib | This directory contains all the library files |
|
||||
| mnt | This directory contains files related to mounted devices on the system |
|
||||
| proc | This directory contains files related to the running processes on the system |
|
||||
| root | This directory contains root user-related files and directories |
|
||||
| sbin | This directory contains programs used for system administration |
|
||||
| tmp | This directory is used to store temporary files on the system |
|
||||
| usr | This directory is used to store application programs on the system |
|
||||
|
||||
## Commands for Navigating the File System
|
||||
|
||||
@@ -70,42 +62,42 @@ file system:
|
||||
|
||||
We will now try to understand what each command does and how to use
|
||||
these commands. You should also practice the given examples on the
|
||||
online bash shell.
|
||||
online Bash shell.
|
||||
|
||||
### pwd (print working directory)
|
||||
|
||||
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.
|
||||
the `pwd` command in Linux.
|
||||
|
||||

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

|
||||
|
||||
### cd (change directory)
|
||||
|
||||
The cd command can be used to change the working directory. Using the
|
||||
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.
|
||||
In the below example, we are initially in the `root` directory. We have
|
||||
then used the `cd` command to change the directory.
|
||||
|
||||

|
||||
|
||||
### ls (list files and directories)**
|
||||
|
||||
The ls command is used to list the contents of a directory. It will list
|
||||
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
|
||||
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
|
||||
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.
|
||||
|
||||

|
||||
@@ -127,17 +119,17 @@ files:
|
||||
|
||||
We will now try to understand what each command does and how to use
|
||||
these commands. You should also practice the given examples on the
|
||||
online bash shell.
|
||||
online Bash shell.
|
||||
|
||||
### touch (create new file)
|
||||
|
||||
The touch command can be used to create an empty new file.
|
||||
This command is very useful for many other purposes but we will discuss
|
||||
The `touch` command can be used to create an empty new file.
|
||||
This command is very useful for many other purposes, but we will discuss
|
||||
the simplest use case of creating a new file.
|
||||
|
||||
General syntax of using touch command
|
||||
General syntax of using `touch` command:
|
||||
|
||||
```
|
||||
```shell
|
||||
touch <file_name>
|
||||
```
|
||||
|
||||
@@ -145,12 +137,12 @@ touch <file_name>
|
||||
|
||||
### mkdir (create new directories)
|
||||
|
||||
The mkdir command is used to create directories.You can use ls command
|
||||
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
|
||||
General syntax of using `mkdir` command:
|
||||
|
||||
```
|
||||
```shell
|
||||
mkdir <directory_name>
|
||||
```
|
||||
|
||||
@@ -158,90 +150,90 @@ mkdir <directory_name>
|
||||
|
||||
### rm (delete files and directories)
|
||||
|
||||
The rm command can be used to delete files and directories. It is very
|
||||
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
|
||||
directories. It's almost impossible to recover these files and
|
||||
directories once you have executed rm command on them successfully. Do
|
||||
directories once you have executed `rm` command on them successfully. Do
|
||||
run this command with care.
|
||||
|
||||
General syntax of using rm command:
|
||||
General syntax of using `rm` command:
|
||||
|
||||
```
|
||||
```shell
|
||||
rm <file_name>
|
||||
```
|
||||
|
||||
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
|
||||
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.
|
||||
|
||||

|
||||
|
||||
### cp (copy files and directories)
|
||||
|
||||
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
|
||||
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
|
||||
original files or directories. The original files or directories and
|
||||
their copy both co-exist after running cp command successfully.
|
||||
their copy both co-exist after running `cp` command successfully.
|
||||
|
||||
General syntax of using cp command:
|
||||
General syntax of using `cp` command:
|
||||
|
||||
```
|
||||
```shell
|
||||
cp <source_path> <destination_path>
|
||||
```
|
||||
|
||||
We are currently in the '/home/runner' directory. We will use the mkdir
|
||||
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
|
||||
We are currently in the `/home/runner` directory. We will use the `mkdir`
|
||||
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.
|
||||
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".
|
||||
inside the `test_directory`.
|
||||
|
||||

|
||||
|
||||
We can also use the cp command to copy the whole directory from one
|
||||
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".
|
||||
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`.
|
||||
|
||||
**mv (move files and directories)**
|
||||
|
||||
The mv command can either be used to move files or directories from one
|
||||
The `mv` command can either be used to move files or directories from one
|
||||
location to another or it can be used to rename files or directories. Do
|
||||
note that moving files and copying them are very different. When you
|
||||
move the files or directories, the original copy is lost.
|
||||
|
||||
General syntax of using mv command:
|
||||
General syntax of using `mv` command:
|
||||
|
||||
```
|
||||
```shell
|
||||
mv <source_path> <destination_path>
|
||||
```
|
||||
|
||||
In this example, we will use the mv command to move the
|
||||
"\_test_runner.py" file to "test_directory". In this case, this file
|
||||
already exists in "test_directory". The mv command will just replace it.
|
||||
In this example, we will use the `mv` command to move the
|
||||
`_test_runner.py` file to `test_directory`. In this case, this file
|
||||
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.**
|
||||
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
|
||||
exist if we use mv command.
|
||||
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
|
||||
exist if we use `mv` command.
|
||||
|
||||
One of the important uses of the mv command is to rename files and
|
||||
One of the important uses of the `mv` command is to rename files and
|
||||
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".
|
||||
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`.
|
||||
|
||||

|
||||
|
||||
@@ -262,9 +254,9 @@ files:
|
||||
|
||||
We will now try to understand what each command does and how to use
|
||||
these commands. You should also practice the given examples on the
|
||||
online bash shell.
|
||||
online Bash shell.
|
||||
|
||||
We will create a new file called "numbers.txt" and insert numbers from 1
|
||||
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.
|
||||
|
||||

|
||||
@@ -277,7 +269,7 @@ later sections.
|
||||
|
||||
### cat
|
||||
|
||||
The most simplest use of cat command is to print the contents of the file on
|
||||
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.
|
||||
|
||||
@@ -289,63 +281,63 @@ all the numbers.
|
||||
|
||||
### head
|
||||
|
||||
The head command displays the first 10 lines of the file by default. We
|
||||
The `head` command displays the first 10 lines of the file by default. We
|
||||
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.
|
||||
file when we use the `head` command.
|
||||
|
||||

|
||||
|
||||
By default, head command will only display the first 10 lines. If we
|
||||
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.
|
||||
`-n` argument to provide the input.
|
||||
|
||||

|
||||
|
||||
### tail
|
||||
|
||||
The tail command displays the last 10 lines of the file by default. We
|
||||
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'
|
||||
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.
|
||||
when we use the `tail` command with explicit `-n` option.
|
||||
|
||||
|
||||
### more
|
||||
|
||||
More command displays the contents of a file or a command output,
|
||||
The `more` command displays the contents of a file or a command output,
|
||||
displaying one screen at a time in case the file is large (Eg: log files).
|
||||
It also allows forward navigation and limited backward navigation in the file.
|
||||
|
||||

|
||||
|
||||
More command displays as much as can fit on the current screen and waits for user input to advance. Forward navigation can be done by pressing Enter, which advances the output by one line and Space, which advances the output by one screen.
|
||||
The `more` command displays as much as can fit on the current screen and waits for user input to advance. Forward navigation can be done by pressing `Enter`, which advances the output by one line and `Space`, which advances the output by one screen.
|
||||
|
||||
### less
|
||||
|
||||
Less command is an improved version of more. It displays the contents of a file or a command output, one page at a time.
|
||||
It allows backward navigation as well as forward navigation in the file and also has search options. We can use arrow keys for advancing backward or forward by one line. For moving forward by one page, press Space and for moving backward by one page, press b on your keyboard.
|
||||
The `less` command is an improved version of `more`. It displays the contents of a file or a command output, one page at a time.
|
||||
It allows backward navigation as well as forward navigation in the file and also has search options. We can use `arrow keys` for advancing backward or forward by one line. For moving forward by one page, press `Space` and for moving backward by one page, press `b` on your keyboard.
|
||||
You can go to the beginning and the end of a file instantly.
|
||||
|
||||
|
||||
## Echo Command in Linux
|
||||
|
||||
The echo command is one of the simplest commands that is used in the
|
||||
shell. This command is equivalent to what we have <print> in other
|
||||
The `echo` command is one of the simplest commands that is used in the
|
||||
shell. This command is equivalent to `print` in other
|
||||
programming languages.
|
||||
|
||||
The echo command prints the given input string on the screen.
|
||||
The `echo` command prints the given input string on the screen.
|
||||
|
||||

|
||||
|
||||
@@ -371,61 +363,61 @@ texts:
|
||||
|
||||
We will now try to understand what each command does and how to use
|
||||
these commands. You should also practice the given examples on the
|
||||
online bash shell.
|
||||
online Bash shell.
|
||||
|
||||
We will create a new file called "numbers.txt" and insert numbers from 1
|
||||
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.
|
||||
|
||||

|
||||
|
||||
### grep
|
||||
|
||||
The grep command in its simplest form can be used to search particular
|
||||
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
|
||||
contains a particular input. The word we want to search is provided as
|
||||
an input to the grep command.
|
||||
an input to the `grep` command.
|
||||
|
||||
General syntax of using grep command:
|
||||
General syntax of using `grep` command:
|
||||
|
||||
```
|
||||
```shell
|
||||
grep <word_to_search> <file_name>
|
||||
```
|
||||
|
||||
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 `grep` command outputs the lines where it found this string.
|
||||
|
||||

|
||||
|
||||
### sed
|
||||
|
||||
The sed command in its simplest form can be used to replace a text in a
|
||||
The `sed` command in its simplest form can be used to replace a text in a
|
||||
file.
|
||||
|
||||
General syntax of using the sed command for replacement:
|
||||
General syntax of using the `sed` command for replacement:
|
||||
|
||||
```
|
||||
```shell
|
||||
sed 's/<text_to_replace>/<replacement_text>/' <file_name>
|
||||
```
|
||||
|
||||
Let's try to replace each occurrence of "1" in the file with "3" using
|
||||
sed command.
|
||||
`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
|
||||
example. To do so, we have to use an extra argument `-i` so that the
|
||||
changes are reflected back in the file.
|
||||
|
||||
### sort
|
||||
|
||||
The sort command can be used to sort the input provided to it as an
|
||||
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
|
||||
Now, we will try to sort the file using the `sort` command. The `sort`
|
||||
command sorts the content in lexicographical order.
|
||||
|
||||

|
||||
@@ -437,11 +429,11 @@ example.
|
||||
|
||||
Each open file gets assigned a file descriptor. A file descriptor is an
|
||||
unique identifier for open files in the system. There are always three
|
||||
default files open, stdin (the keyboard), stdout (the screen), and
|
||||
stderr (error messages output to the screen). These files can be
|
||||
default files open, `stdin` (the keyboard), `stdout` (the screen), and
|
||||
`stderr` (error messages output to the screen). These files can be
|
||||
redirected.
|
||||
|
||||
Everything is a file in linux -
|
||||
Everything is a file in Linux -
|
||||
[https://unix.stackexchange.com/questions/225537/everything-is-a-file](https://unix.stackexchange.com/questions/225537/everything-is-a-file)
|
||||
|
||||
Till now, we have displayed all the output on the screen which is the
|
||||
@@ -449,12 +441,12 @@ standard output. We can use some special operators to redirect the
|
||||
output of the command to files or even to the input of other commands.
|
||||
I/O redirection is a very powerful feature.
|
||||
|
||||
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 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
|
||||
In the below example, we have redirected the output from `echo` command to
|
||||
a file.
|
||||
|
||||

|
||||
@@ -462,13 +454,13 @@ 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 `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
|
||||
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.
|
||||
|
||||

|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Conclusion
|
||||
|
||||
We have covered the basics of Linux operating systems and basic commands used in linux.
|
||||
We have covered the basics of Linux operating systems and basic commands used in Linux.
|
||||
We have also covered the Linux server administration commands.
|
||||
|
||||
We hope that this course will make it easier for you to operate on the command line.
|
||||
@@ -13,12 +13,12 @@ We hope that this course will make it easier for you to operate on the command l
|
||||
4. `tail` command is very useful to view the latest data in the log file.
|
||||
5. Different users will have different permissions depending on their roles. We will also not want everyone in the company to access our servers for security reasons. Users permissions can be restricted with `chown`, `chmod` and `chgrp` commands.
|
||||
6. `ssh` is one of the most frequently used commands for a SRE. Logging into servers and troubleshooting along with performing basic administration tasks will only be possible if we are able to login into the server.
|
||||
7. What if we want to run an apache server or nginx on a server? We will first install it using the package manager. Package management commands become important here.
|
||||
8. Managing services on servers is another critical responsibility of a SRE. Systemd related commands can help in troubleshooting issues. If a service goes down, we can start it using `systemctl start` command. We can also stop a service in case it is not needed.
|
||||
9. Monitoring is another core responsibility of a SRE. Memory and CPU are two important system level metrics which should be monitored. Commands like `top` and `free` are quite helpful here.
|
||||
10. If a service is throwing an error, how do we find out the root cause of the error ? We will certainly need to check logs to find out the whole stack trace of the error. The log file will also tell us the number of times the error has occurred along with time when it started.
|
||||
7. What if we want to run an Apache server or NGINX on a server? We will first install it using the package manager. Package management commands become important here.
|
||||
8. Managing services on servers is another critical responsibility of a SRE. `systemd`-related commands can help in troubleshooting issues. If a service goes down, we can start it using `systemctl start` command. We can also stop a service in case it is not needed.
|
||||
9. Monitoring is another core responsibility of a SRE. Memory and CPU are two important system-level metrics which should be monitored. Commands like `top` and `free` are quite helpful here.
|
||||
10. If a service throws an error, how do we find out the root cause of the error? We will certainly need to check logs to find out the whole stack trace of the error. The log file will also tell us the number of times the error has occurred along with time when it started.
|
||||
|
||||
## Useful Courses and tutorials
|
||||
## Useful Courses and Tutorials
|
||||
|
||||
* [Edx basic linux commands course](https://courses.edx.org/courses/course-v1:LinuxFoundationX+LFS101x+1T2020/course/)
|
||||
* [Edx Red Hat Enterprise Linux Course](https://courses.edx.org/courses/course-v1:RedHat+RH066x+2T2017/course/)
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
## Introduction
|
||||
### Prerequisites
|
||||
|
||||
- Should be comfortable in using any operating systems like Windows, Linux or Mac
|
||||
- Should be comfortable in using any operating systems like Windows, Linux or
|
||||
- Expected to have fundamental knowledge of operating systems
|
||||
|
||||
## What to expect from this course
|
||||
@@ -15,17 +15,17 @@ difference between GUI and CLI.
|
||||
|
||||
In the second part, we cover some basic commands used in Linux.
|
||||
We will focus on commands used for navigating the file system, viewing and manipulating files,
|
||||
I/O redirection etc.
|
||||
I/O redirection, etc.
|
||||
|
||||
In the third part, we cover Linux system administration. This includes day to day tasks
|
||||
In the third part, we cover Linux system administration. This includes day-to-day tasks
|
||||
performed by Linux admins, like managing users/groups, managing file permissions,
|
||||
monitoring system performance, log files etc.
|
||||
|
||||
In the second and third part, we will be taking examples to understand the concepts.
|
||||
In the second and third part, we will be showing examples to understand the concepts.
|
||||
|
||||
## What is not covered under this course
|
||||
|
||||
We are not covering advanced Linux commands and bash scripting in this
|
||||
We are not covering advanced Linux commands and Bash scripting in this
|
||||
course. We will also not be covering Linux internals.
|
||||
|
||||
## Course Contents
|
||||
@@ -69,32 +69,32 @@ Most of us are familiar with the Windows operating system used in more than
|
||||
75% of the personal computers. The Windows operating systems
|
||||
are based on Windows NT kernel.
|
||||
|
||||
A kernel is the most important part of
|
||||
an operating system - it performs important functions like process
|
||||
management, memory management, filesystem management etc.
|
||||
A _kernel_ is the most important part of
|
||||
an operating system—it performs important functions like process
|
||||
management, memory management, filesystem management, etc.
|
||||
|
||||
Linux operating systems are based on the Linux kernel. A Linux based
|
||||
Linux operating systems are based on the Linux kernel. A Linux-based
|
||||
operating system will consist of Linux kernel, GUI/CLI, system libraries
|
||||
and system utilities. The Linux kernel was independently developed and
|
||||
released by Linus Torvalds. The Linux kernel is free and open-source -
|
||||
[https://github.com/torvalds/linux](https://github.com/torvalds/linux)
|
||||
released by Linus Torvalds. The Linux kernel is free and open-source (See
|
||||
[https://github.com/torvalds/linux](https://github.com/torvalds/linux)).
|
||||
|
||||
Linux is a kernel and not a complete operating system. Linux kernel is combined with GNU system to make a complete operating system. Therefore, linux based operating systems are also called as GNU/Linux systems. GNU is an extensive collection of free softwares like compiler, debugger, C library etc.
|
||||
[Linux and the GNU System](https://www.gnu.org/gnu/linux-and-gnu.en.html)
|
||||
Linux is a kernel and not a complete operating system. Linux kernel is combined with GNU system to make a complete operating system. Therefore, Linux-based operating systems are also called as GNU/Linux systems. GNU is an extensive collection of free softwares like compiler, debugger, C library etc. (See
|
||||
[Linux and the GNU System](https://www.gnu.org/gnu/linux-and-gnu.en.html))
|
||||
|
||||
History of Linux -
|
||||
[https://en.wikipedia.org/wiki/History_of_Linux](https://en.wikipedia.org/wiki/History_of_Linux)
|
||||
|
||||
## What are popular Linux distributions
|
||||
|
||||
A Linux distribution(distro) is an operating system based on
|
||||
A Linux distribution (_distro_) is an operating system based on
|
||||
the Linux kernel and a package management system. A package management
|
||||
system consists of tools that help in installing, upgrading,
|
||||
configuring and removing softwares on the operating system.
|
||||
|
||||
Software are usually adopted to a distribution and are packaged in a
|
||||
distro specific format. These packages are available through a distro
|
||||
specific repository. Packages are installed and managed in the operating
|
||||
distro-specific format. These packages are available through a distro-specific
|
||||
repository. Packages are installed and managed in the operating
|
||||
system by a package manager.
|
||||
|
||||
**List of popular Linux distributions:**
|
||||
@@ -116,8 +116,8 @@ system by a package manager.
|
||||
|
||||
| Packaging systems | Distributions | Package manager
|
||||
| ---------------------- | ------------------------------------------ | -----------------
|
||||
| Debian style (.deb) | Debian, Ubuntu | APT
|
||||
| Red Hat style (.rpm) | Fedora, CentOS, Red Hat Enterprise Linux | YUM
|
||||
| Debian style (`.deb`) | Debian, Ubuntu | APT
|
||||
| Red Hat style (`.rpm`) | Fedora, CentOS, Red Hat Enterprise Linux | YUM
|
||||
|
||||
## Linux Architecture
|
||||
|
||||
@@ -141,11 +141,11 @@ Operating system based on Linux kernel are widely used in:
|
||||
|
||||
- Mobile phones - Android is based on Linux operating system
|
||||
|
||||
- Embedded devices - watches, televisions, traffic lights etc
|
||||
- Embedded devices - watches, televisions, traffic lights, etc.
|
||||
|
||||
- Satellites
|
||||
|
||||
- Network devices - routers, switches etc.
|
||||
- Network devices - routers, switches, etc.
|
||||
|
||||
## Graphical user interface (GUI) vs Command line interface (CLI)
|
||||
|
||||
@@ -172,9 +172,9 @@ programs available on Linux servers. Other popular shell programs are
|
||||
zsh, ksh and tcsh.
|
||||
|
||||
Terminal is a program that opens a window and lets you interact with the
|
||||
shell. Some popular examples of terminals are gnome-terminal, xterm,
|
||||
konsole etc.
|
||||
shell. Some popular examples of terminals are GNOME-terminal, xterm,
|
||||
Konsole, etc.
|
||||
|
||||
Linux users do use the terms shell, terminal, prompt, console etc.
|
||||
Linux users do use the terms shell, terminal, prompt, console, etc.
|
||||
interchangeably. In simple terms, these all refer to a way of taking
|
||||
commands from the user.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Linux Server Administration
|
||||
|
||||
In this course will try to cover some of the common tasks that a linux
|
||||
In this course, will try to cover some of the common tasks that a Linux
|
||||
server administrator performs. We will first try to understand what a
|
||||
particular command does and then try to understand the commands using
|
||||
examples. Do keep in mind that it's very important to practice the Linux
|
||||
@@ -8,7 +8,7 @@ commands on your own.
|
||||
|
||||
## Lab Environment Setup
|
||||
|
||||
- Install docker on your system - [https://docs.docker.com/engine/install/](https://docs.docker.com/engine/install/) OR you can used online [Docker playground](https://labs.play-with-docker.com/)
|
||||
- Install docker on your system - [https://docs.docker.com/engine/install/](https://docs.docker.com/engine/install/) OR you can use online [Docker playground](https://labs.play-with-docker.com/)
|
||||
|
||||
- We will be running all the commands on Red Hat Enterprise Linux (RHEL) 8 system.
|
||||
|
||||
@@ -18,7 +18,7 @@ commands on your own.
|
||||
|
||||
## Multi-User Operating Systems
|
||||
|
||||
An operating system is considered as multi-user if it allows multiple people/users to use a computer and not affect each other's files and preferences. Linux based operating systems are multi-user in nature as it allows multiple users to access the system at the same time. A typical computer will only have one keyboard and monitor but multiple users can log in via SSH if the computer is connected to the network. We will cover more about SSH later.
|
||||
An operating system is considered as multi-user if it allows multiple people/users to use a computer and not affect each other's files and preferences. Linux-based operating systems are multi-user in nature as it allows multiple users to access the system at the same time. A typical computer will only have one keyboard and monitor but multiple users can log in via SSH if the computer is connected to the network. We will cover more about SSH later.
|
||||
|
||||
As a server administrator, we are mostly concerned with the Linux servers which are physically present at a very large distance from us. We can connect to these servers with the help of remote login methods like SSH.
|
||||
|
||||
@@ -37,26 +37,28 @@ Since Linux supports multiple users, we need to have a method which can protect
|
||||
|
||||
### id command
|
||||
|
||||
`id` command can be used to find the uid and gid associated with an user.
|
||||
`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.
|
||||
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
|
||||
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**
|
||||
**`root` user or superuser is the most privileged user with**
|
||||
**unrestricted access to all the resources on the system. It has UID 0**
|
||||
|
||||
### Important files associated with users/groups
|
||||
|
||||
| /etc/passwd | Stores the user name, the uid, the gid, the home directory, the login shell etc |
|
||||
| -------------| ---------------------------------------------------------------------------------
|
||||
| /etc/shadow | Stores the password associated with the users |
|
||||
| /etc/group | Stores information about different groups on the system |
|
||||
| Files | Description |
|
||||
|--------------|----------------------------------------------------------------------------------------|
|
||||
| /etc/passwd | Stores the user name, the `uid`, the `gid`, the home directory, the login shell etc |
|
||||
| /etc/shadow | Stores the password associated with the users |
|
||||
| /etc/group | Stores information about different groups on the system |
|
||||
|
||||

|
||||
|
||||
@@ -64,7 +66,7 @@ command.
|
||||
|
||||

|
||||
|
||||
If you want to understand each filed discussed in the above outputs, you can go
|
||||
If you want to understand each field discussed in the above outputs, you can go
|
||||
through below links:
|
||||
|
||||
- [https://tldp.org/LDP/lame/LAME/linux-admin-made-easy/shadow-file-formats.html](https://tldp.org/LDP/lame/LAME/linux-admin-made-easy/shadow-file-formats.html)
|
||||
@@ -77,21 +79,18 @@ Some of the commands which are used frequently to manage users/groups
|
||||
on Linux are following:
|
||||
|
||||
- `useradd` - Creates a new user
|
||||
|
||||
- `passwd` - Adds or modifies passwords for a user
|
||||
|
||||
- `usermod` - Modifies attributes of an user
|
||||
|
||||
- `userdel` - Deletes an user
|
||||
|
||||
### useradd
|
||||
|
||||
The useradd command adds a new user in Linux.
|
||||
The `useradd` command adds a new user in Linux.
|
||||
|
||||
We will create a new user 'shivam'. We will also verify that the user
|
||||
has been created by tailing the /etc/passwd file. The uid and gid are
|
||||
We will create a new user `shivam`. We will also verify that the user
|
||||
has been created by tailing the `/etc/passwd` file. The `uid` and `gid` are
|
||||
1000 for the newly created user. The home directory assigned to the user
|
||||
is /home/shivam and the login shell assigned is /bin/bash. Do note that
|
||||
is `/home/shivam` and the login shell assigned is `/bin/bash`. Do note that
|
||||
the user home directory and login shell can be modified later on.
|
||||
|
||||

|
||||
@@ -104,17 +103,17 @@ override these default values when creating a new user.
|
||||
|
||||
### passwd
|
||||
|
||||
The passwd command is used to create or modify passwords for a 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.
|
||||
`shivam` or `amit` while creating them.
|
||||
|
||||
"!!" in an account entry in shadow means the account of an user has
|
||||
`!!` 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".
|
||||
Let's now try to create a password for user `shivam`.
|
||||
|
||||

|
||||
|
||||
@@ -129,118 +128,118 @@ Also, when you login using root user, the password will be asked.
|
||||
|
||||
### usermod
|
||||
|
||||
The usermod command is used to modify the attributes of an user like the
|
||||
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".
|
||||
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.
|
||||
Try `usermod -h` for a list of attributes you can modify.
|
||||
|
||||
### userdel
|
||||
|
||||
The userdel command is used to remove a user on Linux. Once we remove a
|
||||
The `userdel` command is used to remove a user on Linux. Once we remove a
|
||||
user, all the information related to that user will be removed.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||

|
||||
|
||||
## Important commands for managing groups
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
|
||||
| groupadd \<group_name\> | Creates a new group |
|
||||
| ------------------------ | ------------------------------- |
|
||||
| groupmod \<group_name\> | Modifies attributes of a group |
|
||||
| groupdel \<group_name\> | Deletes a group |
|
||||
| gpasswd \<group_name\> | Modifies password for group |
|
||||
| Command | Description |
|
||||
| -----------------------| ------------------------------- |
|
||||
| groupadd <group_name\> | Creates a new group |
|
||||
| groupmod <group_name\> | Modifies attributes of a group |
|
||||
| groupdel <group_name\> | Deletes a group |
|
||||
| gpasswd <group_name\> | Modifies password for group |
|
||||
|
||||

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

|
||||
|
||||
## Becoming a Superuser
|
||||
|
||||
**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
|
||||
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".
|
||||
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.
|
||||
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
|
||||
users who have the superuser privileges.
|
||||
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
|
||||
users who have the `superuser` privileges.
|
||||
|
||||
|
||||
**The sudo command allows a** **user to run commands with the security
|
||||
**The `sudo` command allows a** **user to run commands with the security
|
||||
privileges of the root user.** Do remember that the root user has all
|
||||
the privileges on a system. We can also use su command to switch to the
|
||||
the privileges on a system. We can also use `su` command to switch to the
|
||||
root user and open the above file but doing that will require the
|
||||
password of the root user. An alternative way which is preferred on most
|
||||
modern operating systems is to use sudo command for becoming a
|
||||
modern operating systems is to use `sudo` command for becoming a
|
||||
superuser. Using this way, a user has to enter his/her password and they
|
||||
need to be a part of the sudo group.
|
||||
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
|
||||
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
|
||||
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.
|
||||
`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.
|
||||
**The file `/etc/sudoers` holds the names of users permitted to invoke
|
||||
`sudo`**. In Red Hat 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.
|
||||
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
|
||||
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
|
||||
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.
|
||||
which has permissions to run all the commands. `wheel` is a group in
|
||||
Red Hat Linux with such privileges.
|
||||
|
||||

|
||||
|
||||
Let's add the user "shivam" to this group so that it also has sudo
|
||||
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.
|
||||
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”.
|
||||
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`.
|
||||
|
||||
|
||||
## File Permissions
|
||||
@@ -250,8 +249,8 @@ permissions for the owner of the file, the members of a group of related
|
||||
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.
|
||||
To see the permissions of a file, we can use the `ls` command. Let's look
|
||||
at the permissions of `/etc/passwd` file.
|
||||
|
||||

|
||||
|
||||
@@ -265,10 +264,10 @@ related to file permissions.
|
||||
|
||||
### Chmod command
|
||||
|
||||
The chmod command is used to modify files and directories permissions in
|
||||
The `chmod` command is used to modify files and directories permissions in
|
||||
Linux.
|
||||
|
||||
The chmod command accepts permissions in as a numerical argument. We can
|
||||
The `chmod` command accepts permissions in as a numerical argument. We can
|
||||
think of permission as a series of bits with 1 representing True or
|
||||
allowed and 0 representing False or not allowed.
|
||||
|
||||
@@ -288,26 +287,26 @@ 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
|
||||
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
|
||||
`chmod` command can be also used to change the permissions of a directory
|
||||
in the similar way.
|
||||
|
||||
### Chown command
|
||||
|
||||
The chown command is used to change the owner of files or
|
||||
The `chown` command is used to change the owner of files or
|
||||
directories in Linux.
|
||||
|
||||
Command syntax: chown \<new_owner\> \<file_name\>
|
||||
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
|
||||
**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.
|
||||
|
||||

|
||||
@@ -317,53 +316,53 @@ similar way.
|
||||
|
||||
### Chgrp command
|
||||
|
||||
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
|
||||
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
|
||||
`chgrp` command can also be used to change the owner of a directory in the
|
||||
similar way.
|
||||
|
||||
## SSH Command
|
||||
|
||||
The ssh command is used for logging into the remote systems, transfer files between systems and for executing commands on a remote machine. SSH stands for secure shell and is used to provide an encrypted secured connection between two hosts over an insecure network like the internet.
|
||||
The `ssh` command is used for logging into the remote systems, transfer files between systems and for executing commands on a remote machine. `SSH` stands for secure shell and is used to provide an encrypted secured connection between two hosts over an insecure network like the internet.
|
||||
|
||||
Reference:
|
||||
[https://www.ssh.com/ssh/command/](https://www.ssh.com/ssh/command/)
|
||||
|
||||
We will now discuss passwordless authentication which is secure and most
|
||||
commonly used for ssh authentication.
|
||||
commonly used for `ssh` authentication.
|
||||
|
||||
### Passwordless Authentication Using SSH
|
||||
|
||||
Using this method, we can ssh into hosts without entering the password.
|
||||
Using this method, we can `ssh` into hosts without entering the password.
|
||||
This method is also useful when we want some scripts to perform
|
||||
ssh-related tasks.
|
||||
|
||||
Passwordless authentication requires the use of a public and private key pair. As the name implies, the public key can be shared with anyone but the private key should be kept private.
|
||||
Lets not get into the details of how this authentication works. You can read more about it
|
||||
Let's not get into the details of how this authentication works. You can read more about it
|
||||
[here](https://www.digitalocean.com/community/tutorials/understanding-the-ssh-encryption-and-connection-process)
|
||||
|
||||
Steps for setting up a passwordless authentication with a remote host:
|
||||
|
||||
1. Generating public-private key pair
|
||||
|
||||
**If we already have a key pair stored in \~/.ssh directory, we will not need to generate keys again.**
|
||||
**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.
|
||||
Install `openssh` package which contains all the commands related to `ssh`.
|
||||
|
||||

|
||||
|
||||
Generate a key pair using the ssh-keygen command. One can choose the
|
||||
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
|
||||
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.
|
||||
|
||||

|
||||
@@ -372,40 +371,48 @@ Steps for setting up a passwordless authentication with a 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-copy-id command.
|
||||
`ssh-copy-id` command.
|
||||
|
||||

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

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

|
||||
|
||||
Now, ssh into the remote host using the password authentication.
|
||||
Now, `ssh` into the remote host using the password authentication.
|
||||
|
||||

|
||||
|
||||
Our public key should be there in \~/.ssh/authorized_keys now.
|
||||
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
|
||||
`~/.ssh/authorized_key` contains a list of public keys. The users
|
||||
associated with these public keys have the `ssh` access into the remote
|
||||
host.
|
||||
|
||||
|
||||
### How to run commands on a remote host ?
|
||||
|
||||
General syntax: ssh \<user\>@\<hostname/hostip\> \<command\>
|
||||
General syntax:
|
||||
|
||||
```shell
|
||||
ssh \<user\>@\<hostname/hostip\> \<command\>
|
||||
```
|
||||
|
||||

|
||||
|
||||
### How to transfer files from one host to another host ?
|
||||
|
||||
General syntax: scp \<source\> \<destination\>
|
||||
General syntax:
|
||||
|
||||
```shell
|
||||
scp \<source\> \<destination\>
|
||||
```
|
||||
|
||||

|
||||
|
||||
@@ -418,32 +425,32 @@ systems.
|
||||
|
||||
| Packaging systems | Distributions |
|
||||
| ---------------------- | ------------------------------------------ |
|
||||
| Debian style (.deb) | Debian, Ubuntu |
|
||||
| Red Hat style (.rpm) | Fedora, CentOS, Red Hat Enterprise Linux |
|
||||
| Debian style (`.deb`) | Debian, Ubuntu |
|
||||
| Red Hat style (`.rpm`) | Fedora, CentOS, Red Hat Enterprise Linux |
|
||||
|
||||
**Popular Packaging Systems in Linux**
|
||||
|
||||
|Command | Description |
|
||||
| ----------------------------- | --------------------------------------------------- |
|
||||
| yum install \<package_name\> | Installs a package on your system |
|
||||
| yum update \<package_name\> | Updates a package to it's latest available version |
|
||||
| yum remove \<package_name\> | Removes a package from your system |
|
||||
| yum search \<keyword\> | Searches for a particular keyword |
|
||||
| yum install <package_name\> | Installs a package on your system |
|
||||
| yum update <package_name\> | Updates a package to its latest available version |
|
||||
| yum remove <package_name\> | Removes a package from your system |
|
||||
| yum search <keyword\> | Searches for a particular keyword |
|
||||
|
||||
[DNF](https://docs.fedoraproject.org/en-US/quick-docs/dnf/) is
|
||||
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
|
||||
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.
|
||||
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.
|
||||
After `httpd` is installed, we will use the `yum remove` command to remove
|
||||
`httpd` package.
|
||||
|
||||

|
||||
|
||||
@@ -454,15 +461,15 @@ used to monitor the processes on Linux systems.
|
||||
|
||||
### ps (process status)
|
||||
|
||||
The ps command is used to know the information of a process or list of
|
||||
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.
|
||||
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
|
||||
`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:
|
||||
@@ -470,28 +477,28 @@ Reference:
|
||||
|
||||

|
||||
|
||||
We can use an additional argument with ps command to list the
|
||||
information about the process with a specific process ID.
|
||||
We can use an additional argument with `ps` command to list the
|
||||
information about the process with a specific process ID (PID).
|
||||
|
||||

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

|
||||
|
||||
### top
|
||||
|
||||
The top command is used to show information about Linux 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
|
||||
whole along with system uptime and cpu load average.
|
||||
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
|
||||
whole along with system uptime and CPU load average.
|
||||
|
||||
## Memory Management
|
||||
|
||||
@@ -500,21 +507,21 @@ used to view information about the system memory.
|
||||
|
||||
### free
|
||||
|
||||
The free command is used to display the memory usage of the system. The
|
||||
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
|
||||
`free` command by default shows the memory usage in kilobytes. We can use
|
||||
an additional argument to get the data in human-readable format.
|
||||
|
||||

|
||||
|
||||
### vmstat
|
||||
|
||||
The vmstat command can be used to display the memory usage along with
|
||||
additional information about io and cpu usage.
|
||||
The `vmstat` command can be used to display the memory usage along with
|
||||
additional information about IO and CPU usage.
|
||||
|
||||

|
||||
|
||||
@@ -525,27 +532,27 @@ used to view disk space on Linux.
|
||||
|
||||
### df (disk free)
|
||||
|
||||
The df command is used to display the free and available space for each
|
||||
The `df` command is used to display the free and available space for each
|
||||
mounted file system.
|
||||
|
||||

|
||||
|
||||
### du (disk usage)
|
||||
|
||||
The du command is used to display disk usage of files and directories on
|
||||
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.
|
||||
in the `root` directory.
|
||||
|
||||

|
||||
|
||||
## Daemons
|
||||
|
||||
A computer program that runs as a background process is called a daemon.
|
||||
Traditionally, the name of daemon processes ended with d - sshd, httpd
|
||||
A computer program that runs as a background process is called a _daemon_.
|
||||
Traditionally, the name of daemon processes ends with `d` - `sshd`, `httpd`,
|
||||
etc. We cannot interact with a daemon process as they run in the
|
||||
background.
|
||||
|
||||
@@ -553,12 +560,12 @@ Services and daemons are used interchangeably most of the time.
|
||||
|
||||
## Systemd
|
||||
|
||||
Systemd is a system and service manager for Linux operating systems.
|
||||
Systemd units are the building blocks of systemd. These units are
|
||||
`systemd` is a system and service manager for Linux operating systems.
|
||||
`systemd` units are the building blocks of `systemd`. These units are
|
||||
represented by unit configuration files.
|
||||
|
||||
The below examples shows the unit configuration files available at
|
||||
/usr/lib/systemd/system which are distributed by installed RPM packages.
|
||||
`/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.
|
||||
|
||||
@@ -566,8 +573,8 @@ as these are service units.
|
||||
|
||||
### Managing System Services
|
||||
|
||||
Service units end with .service file extension. Systemctl command can be
|
||||
used to start/stop/restart the services managed by systemd.
|
||||
Service units end with `.service` file extension. `systemctl` command can be
|
||||
used to start/stop/restart the services managed by `systemd`.
|
||||
|
||||
| Command | Description |
|
||||
| ------------------------------- | -------------------------------------- |
|
||||
|
||||
Reference in New Issue
Block a user