Linux For DevOps Engineer
Keyboard Options
Keyboard Symbols
Symbol | Explanation |
~ | Tilde |
` | Back quote |
! | Exclamation mark, exclamation point, or bang. |
@ | At symbol |
& | Ampersand |
* | Wildcard, Asterisk, Star, multiplication |
| | Pipe |
$ | Dollar Sign |
Symbol | Explanation |
? | Question Mark |
( | Open or left parenthesis |
) | Close or right parenthesis |
{ | Open brace or curly bracket |
} | Close brace or curly bracket |
[ | Open bracket |
] | Close bracket |
. | Period or dot |
Keyboard Symbols
Symbol | Explanation |
\ | Backslash |
/ | Forward slash |
! | Exclamation mark, exclamation point, or bang. |
: | Colon |
" | Double quote |
' | Single quote |
; | Semicolon |
, | Comma |
Symbol | Explanation |
_ | Underscore |
+ | Plus |
- | Hyphen or dash or minus |
= | equal |
== | Double equal |
# | Pound or hash |
% | Percent |
Backspace | Backspace (or Backspace) key |
Keyboard Symbols
Symbol | Explanation |
< | Less than |
> | Greater than |
>> | Greater than or equal to |
<< | Less than equal to |
!= | Not equal to |
ctrl+l | Clear Linux Terminal |
ctrl+shift+t | Open google page that you close it |
ctrl+c | Cancel |
ctrl+z | undo |
Symbol | Explanation |
tab | Tabulation or tab key |
ctrl+c | Copy clipboard |
ctrl+v | Past from clipboard |
esc | Esc (escape) key |
arrows | Up, down, left, right Arrow keys. |
Backspace | Backspace (or Backspace) key |
Num Lock | Num Lock key |
ctrl+s | save |
ctrl+y | redo |
Keyboard Symbols
GUI and CLI
GUI Vs CLI
In IT world, GUI stand for graphical user interface; It is an interface through which a user interacts with electronic devices such as computers and smartphones through the use of icons, menus and other visual indicators or representations (graphics)
In IT world, CLI stand for command line interface. It is a text-based interface that is used to operate software and operating systems while allowing the user to respond to visual prompts by typing single commands into the interface and receiving a reply in the same way.
GUI Vs CLI
GUI Vs CLI
CLI | GUI |
Interaction is by typing commands | Interaction with devices is by graphics and visual components and icons |
Commands need to be memorized | Visual indicators and icons are easy to understand |
Use a lot less memory to store programs | Use large amount of memory due to graphics |
Use of keyboard for commands makes CLI quicker | Use of mouse for interaction makes it slow |
Only keyboard is used | Mouse and keyboard is used |
Command line interface does not change, remains same over time | Structure and design can change with updates |
With a CLI, users have all the control over the filesystem and operating system, and the tasks become simple. You can create a script that contains a few lines of command and it will do the work for you | Although GUI’s can create shortcuts, they do not readily support scripting or automation. For commontasks, a user must repeat each action within the GUI manually |
Linux Distributions
What is Linux?
What Linux?
In 1969, Ken Thompson and Dennis Ritchie Created the first version of Unix OS (Ken Thompson and Dennis Ritchie are considered the inventors of Unix.).
The system was multitasking and multi-users which means it could support multi-user at the same time. This makes it very popular and a lot of companies start creating their own version. For example, HP created HP-UX, IBM created AIX, solaris created Oracle, Apple created MAC OS.
Unix was a close source and Linus Torvalds was not satisfied, and he started developing his own version of software, and he came out with Linux software 1991. He released the Linux project under the GNU project or Licence or GPL(general public licence). Since then, they have been a lot of modifications of the linux software and this gave birth to some Linux flavor or distributions that we are using today such as: CentOS which is the clone of Redhat, Ubuntu, Fedora, Debian, Opensuse, Linux Mint, Kali and so on.
UNIX Distributions (close source): Apple Mac OS (created by Apple), Oracle Solaris (created by Oracle), Oracle Solaris (created by Oracle), AIX (created by IBM)
Linux creation announcement by Torvalds
“Starting this Thanksgiving I am going to write a complete Unix-compatible software system called GNU (for Gnu's Not Unix), and give it away free to everyone who can use it. Contributions of time, money, programs and equipment are greatly needed.”
Why Use Linux?
This is the one question that most people ask. Why bother learning a completely different computing environment, when the operating system that ships with most desktops, laptops, and servers works just fine?
To answer that question, I would pose another question. Does that operating system you’re currently using really work “just fine”? Or, do you find yourself battling obstacles like viruses, malware, slow downs, crashes, costly repairs, and licensing fees?
If you struggle with the above, Linux might be the perfect platform for you. Linux has evolved into one of the most reliable computer ecosystems on the planet. Combine that reliability with zero cost of entry and you have the perfect solution for a desktop platform.
That’s right, zero cost of entry… as in free. You can install Linux on as many computers as you like without paying a cent for software or server licensing.
Let just say thanks to Torvalds
What is a Distribution?
Linux has a number of different versions to suit any type of user, you’ll find a “flavor” of Linux to match your needs. These versions are called distributions (or, in the short form, “distros”). Nearly every distribution of Linux can be downloaded for free, burned onto disk (or USB thumb drive), and installed (on as many machines as you like).
What are the most Popular Linux Distro?
What are the most Popular Linux Distro?
What are the most Popular Linux Distro?
Linux Vs Windows Vs Unix
What is Linux?
It is an open-source and free operating system (OS) that provides its users with c compatibility with the user interface and programming interface. It is based on the Unix standards and consists of many elements that are developed separately. It is mostly used for servers. It was created in created in 1991 by Torvalds
Linux Vs Windows Vs Unix
What is Windows?
It is a licensed OS with an inaccessible source code. Windows works pretty well for all users who have very little to no computer knowledge. It is good for commercial use among businesses as well as for personal use. It is very straightforward and easy to use. Windows is software owned by Microsoft and it was created in 1985. No matter how many talented developers Microsoft hires, finding exploits will never be as fast as in Linux since there is a big community behind it.
What is Unix?
Unix is a powerful and multitasking operating system that behaves like a bridge between the user and the computer. It allows the user to perform specific functions. This operating system was launched in 1960, and was released by AT&T Bell Labs.
Linux Vs Windows
Linux | Windows |
Linux is a open source operating system | While windows are the not the open source operating system |
Linux is free of cost | While it is costly |
Linux was created in 1991 by Torvalds | Windows was created in 1985 by Microsoft |
Linux in case-sensitive | Windows do not care about case-sensitive |
Linux is more efficient in comparison of windows | While windows are less efficient |
Linux can run for a very long time without restarting | While Microsoft will even force and restart windows users PC for updates |
There is a forward slash ( / ) is used for Separating the directories. | While there is backslash ( \ ) is used for Separating the directories. |
Linux is highly secure as compared to Windows | While it provides less security than linux |
Linux is widely used in hacking purpose based systems | While windows does not provide much efficiency in hacking |
Linux Vs Windows
Linux | Windows |
There are 3 types of user account – (1) Regular , (2) Root , (3) Service account | There are 4 types of user account – (1) Administrator , (2) Standard , (3) Child , (4) Gues |
Root user is the super user and has all administrative privileges | Administrator user has all administrative privileges of computers. |
Linux is used for servers | While Windows is mostly used for home PC |
Linux file naming convention in case sensitive. Thus, sample and SAMPLE are 2 different files in Linux/Unix operating system | In Windows, you cannot have 2 files with the same name in the same folder |
Linux is based on a multi-user architecture, making it way more stable than a single-user OS like Windows. As Linux is community-driven with regular monitoring by the developers from every corner of the earth, any new problem raised can be solved within a few hours and the necessary patch can be ready for supply.
Why Linux is more secure than Windows?
Linux Vs Windows
Same as Windows
Linux Vs Unix
Features | Linux | Unix |
Launched by | This operating system was launched by Linus Torvalds at the University of Helsinki in 1991. | This operating system was launched in 1960 and released by AT&T Bell Labs. |
Written in | C and other programming languages | C and other programming languages |
Usage | It is used in several systems like desktop, smartphones, mainframes and servers | Unix is majorly used on workstations and servers. |
Examples | Some examples of Linux are: Fedora, Debian, Red Hat, Ubuntu, Android, etc. | Some examples of unix are IBM AIX, Darwin, Solaris, HP-UX, macOS X, etc. |
Security | Linux provides higher security | Unix is also highly secured |
Price | Linux is free and its corporate support is available at any time by the community | Unix is not totally free. There are some Unix versions that are not free such as Mac OS, other than that UNIX is expensive. |
Linux File System
Linux File System
Linux File System
This is a well organized and structured closet. Linux file system looks the same
Linux File System
Linux File System
ROOT (/) it's like a C drive-in window. It can read, write or execute any program
HOME: That's where the regular user's home folders are stored. The ROOT is where the root's home folder is stored.
ETC: it is where most programs keep their configuration files
BIN: it is where regular user commands are stored (executable programs are stored in BIN AND SBIN)
SBIN: it is where root user commands are stored (executable programs are stored in BIN AND SBIN)
DEV: it is where the system keeps references to all the hardware it has such as hard drives, memory, CPUs, and everything else.
MNT: You may also need to work in the mnt folder which is where local or network filesystems are mounted into the overall system or the media folder where removable file systems like USB drives and optical drives are mounted.
TMP: it is a temporary directory. It contains temporary data that will be erased when you reboot your computer
USR: user directory. It contains user data and programs
VAR: variable data directory. It is where the system must be able to write files and folders during operation. It's the system LOG
LIB: it is where 32-bit programs are installed
LIB64: it is where 64-bit programs are installed
Terminology
What is Client and server machine?
Client Machine:
Server or Node or Host:
What is a Datacenter?
Where does company store all the servers?
Datacenter:
It is where we have all the servers for an organization or where we have a massive server or node for a company or heard of the business.
It a good idea to store servers in the datacenter today
What is a Cloud Computing?
Simply put, cloud computing is the delivery of computing services including servers, storage, databases, networking, software over the Internet (“the cloud”) to offer faster innovation, flexible resources, and economies of scale.
Some issues before cloud computing:
Pros of cloud computing:
What is On premise?
On Promise:
What is a hybrid cloud?
What is a File, Folder and Directory?
A file Also known as a "document" is an object on a computer that stores data, information, settings, or commands used with a computer program.
Directory. Also known as a "folder", a directory is a container that stores files and directories.
PS: A folder is called directory in Linux.
What is a SSH?
How can I connect to a remote server using a client machine?
What is SSH?
How to Connect to a Server Using SSH?
You need the following to connect to a remote server:
Command to login using SSH:
What is a port?
ssh-keygen -R server3.anomicatech.com
File and Directory Naming Convention in Linux or In IT
How can I name file and directories in Linux or in IT
What is Case Sensitive in Linux Or IT?
Case Sensitive in Linux
The Linux operating system provides you with multiple commands that you can run in the terminal to find a specific file. Although, most of these commands are case sensitive, meaning that you need to know the exact name of your file and whether it is in lower-case or upper-case letters or a combination of both
Linux is case sensitive because 'a' and 'A'
"Computer" and "computer" are two different words because the "C" is uppercase in the first example and lowercase in the second example
What is a Terminal?
A Terminal
It is an interface in linux that a user interact with the operating system and received an output.
Here are couples of nickname or aliases in linux environment that when pronounced refer to the terminal:
What is a Command and Option In Linux?
A Command:
Options:
An Option
Kernel and Shell In Linux
Shell
Kernel
Type of Shell In Linux
Types of Shell
There are two main shells in Linux:
The Bourne Shell (The prompt for this shell is $) and The C shell. Bourne Shell derivatives are listed below:
root@EK-TECH-SERVER04:~# cat /etc/shells
/bin/sh
/bin/bash
/bin/rbash
/bin/dash
/usr/bin/tmux
/usr/bin/screen
Why bash is a default shell in Linux?
Root User and Regular User In Linux
Root user or admin user or power user or superuser
Regular user or non root user or normal user
User and Root Home directory In Linux
Root user home directory
Regular home directory
Help in Linux
How can I get Help in Linux?
I need help
How can I get Help in Linux?
man
man command
Example: # man [command]
# man ls
Options: # man test
How can I get Help in Linux?
info
info command
Example: # info [command]
# info ls
Options: none
DevOps Linux Commands
What are some command that you need as a feature DevOps?�As DevOps, You do not need to know all linux Commands because you are not a Linux system admin. Linux help you to get your job done and you need to know the basic or the foundation.
Day to day activity commands for DevOps Engineer
DevOps use This commands some time
These are the Linux commands that you need to know to get your job done as a DevOps Engineer
Relative path
Relative path starts from the current directory and goes up to the actual object. Relative path depends on the current directory. When we change the directory, relative path also changes
What is a Relative Path?
What is an absolute Path?
Absolute Path
Absolute path starts from the directory root (/) and goes up to the actual object (file or directory). It contains the names of all directories that come in the middle of the directory root and the actual object. In this, name of the parent directory is written in the left.
Absolute and Relative Path
Linux Basic Commands
Linux Commands
clear
clear command
Example: # clear
# ctrl + l
Options: none
history command
Linux Commands
history
Example: # history
Options: none
exit command
Linux Commands
exit
Example: # history
Options: none
ls command
Example: # ls ----- will list content of current directory
# ls [directory_name] ---will list the content of [directory_name]
Options:
Linux Commands
ls
cd
cd command
Example: # cd [directory_name or path]
# cd /root/tmp ----- to move to tmp directory
# cd ~/Download ----- to move to download directory
# cd /home/Download ----- to move to download directory
Options:
Options:
Linux Commands
touch command
Linux Commands
touch
Example: # touch [file_name]
# touch engineering.txt
Ps: you don't really need to put the file extension because Linux do not care about file extension if it as a regular file
Options: none
mkdir command
Linux Commands
touch
Example: # mkdir [directory_name]
# mkdir manager
Options: # mkdir -p [path]
# mkdir /tmp/tia ⇒ This will help create a directory with the path. The parent directory must exist first
cat command
Linux Commands
cat
Example: # cat [file_name]
# cat [file_path]
# cat logs.txt
Options: none
less command
Linux Commands
less
Example: # less [directory_name]
# less [file_path]
# less logs.txt
Options: none
more command
Linux Commands
more
Example: # more [directory_name]
# more [file_path]
# more logs.txt
Options: none
nl command
Linux Commands
nl
Example: # nl [directory_name]
# nl [file_path]
# nl logs.txt
Options: none
cp command
Linux Commands
cp
Example: # cp -r [directory_name or directory_name]
# cp [file_path or directory_path]
# cp logs.txt /tmp ⇒ copy logs.txt to tmp directory
# cp -r ~/home/tia/manager /tmp ⇒ copy manager in tia home directory to the tmp directory
Options: # cp -r
r = recursive. It means copy the parent and all the subdirectories
cp options
Linux Commands
cp
Options:
# cp -r manager /tmp ⇒ copy the directory manager to the tmp directory
# cp * /tmp ⇒ copy everything in my current working directory to the tmp directory
# cp -r manager/* /tmp ⇒ copy everything in manager to the tmp directory
# cp *.txt /tmp ⇒ copy all files that ends with .txt in in my current working directory to tmp
# cp *.sh /tmp ⇒ copy all files that ends with .sh in in my current working directory to tmp
# cp *a /tmp ⇒ copy all files that ends with a in in my current working directory to tmp
# cp a* /tmp ⇒ copy all files that starts with a in in my current working directory to tmp
r = recursive. It means copy the parent and all the subdirectories
cp options with path
Linux Commands
Options:
# cp -r ~/Desktop/manager /tmp ⇒ copy the directory manager from Desktop to the tmp directory
# cp -r ~/home/tia/* /tmp ⇒ copy everything in my tia directory to the tmp directory
# cp -r manager/* /tmp ⇒ copy everything in manager directory to the tmp directory
# cp -r manager/* . ⇒ copy everything in manager directory and put in my current working directory
# cp /tia/script/*.txt /tmp ⇒ copy all files that ends with .txt in script directory to the tmp directory
# cp *.sh /home/Desktop/scripts ⇒ copy all files that ends with .sh in the script directory on my desktop
# cp ~/*.sh /home/Desktop/scripts ⇒ copy all files that ends with .sh in tom home directory on my desktop
# cp /root/*a /tmp ⇒ copy all files that ends with a in root home directory to tmp directory
r = recursive. It means copy the parent and all the subdirectories
cp
mv
Linux Commands
Options:
The command mv stands for move. The mv is used to move one or more files or directories from one place to another. It is also used to rename files and directories
Example : # mv file1 file2 ------ this will rename file1 to file2
# mv file1 folder2 ----this will move file1 to directory folder2
Options:
# mv * /tmp ⇒ move everything in my current working directory to the tmp directory
# mv -r manager/* /tmp ⇒ move everything in manager to the tmp directory
# mv *.txt /tmp ⇒ move all files that ends with .txt in in my current working directory to tmp
# mv *.sh /tmp ⇒ move all files that ends with .sh in in my current working directory to tmp
# mv *a /tmp ⇒ move all files that ends with a in in my current working directory to tmp
# mv a* /tmp ⇒ move all files that starts with a in in my current working directory to tmp
rm , rm -rf and echo
Linux Commands
Options:
The rm (remove) command is used to delete files only
The rm -rf command is used to delete files and or directories
Example : # rm [file_name]
Example : # rm -rf [file_name] or # rm -rf [directory_name]
The echo is used to display or print text (string) on the terminal
Example : # echo [“text_to_display”]
env, export and unset
Linux Commands
The env command in Linux is used to print environment variables or system variables
Example : # env
The export command is a built-in utility of Linux Bash shell. It is used to set the environment variables or system variables in Linux
Example : # export [env_name]=[value]
The unset command is a built-in utility of Linux Bash shell. It is used to delete or remove the environment variables or system variables in Linux
Example : # unset [env_name]
Options:
head and tail
Linux Commands
The head command in Linux is used to view the first 10 lines of a file by default
Example : # head [file_name]
The tail command in Linux is used to view last 10 lines of a file by default
Example : # tail [file_name]
Options:
wc, whoami and who
Linux Commands
The wc command is used to count words, lines and characters in the file
Example : # wc [argument]
The whoami is a compound of the words “Who am I?” and prints the name of the user that is currently login
Example : # whoami
The w or who command will display the name of all the users that are currently login
Example : # w
su is the command in linux used to switch for one user to another or also run command on behalf of other user
Example # su - [username]
# su - root
Options:
Uname, hostname, nproc , arch
Linux Commands
The uname command is used to display the system information such as the kernel version, the system architecture etc.
Example : # uname
The hostname command is used to display the hostname name of the server.
Example : # hostname
The arch or getconf LONG_BIT is used to get the current computer architecture.
Example : # arch
The nproc command is used to get the the number of CPU that the server is using.
Example : # nproc
Options:
append and redirect
Linux Commands
“>“: Overwrites the existing file, or creates a file if the file of the mentioned name is not present in the directory.
“>>“: Appends the existing file, or creates a file if the file of the mentioned name is not present in the directory.
While making modifications in a file and you want to overwrite the existing data, then use the “>” operator. If you want to append something to that file, use the “>>” operator
The “>” is an output operator that overwrites the existing file, while “>>” is also an output operator but appends the data in an already existing file. Both operators are often used to modify the files in Linux.
> file.txt: to empty a file cat >> demo.txt cat > demo.txt
ctrl + d: to save
tar, zip and unzip
Linux Commands
The zip command is used to compress a file in Linux
Example : # zip -r my_file.zip tia-devops
The unzip command is used to extract the zip file in Linux
Example : # unzip my_file.zip
The tar command is used to compress a file in Linux
Example : # tar cf [file_name.tar] [file_name]
# tar -cpzf tia-devops.tar tia-devops
# tar -cpzf tia-devops.gz tia-devops
# tar -xpzf tia-devops.tar
# tar -xpzf tia-devops.gz
Options:
Naming Files with time = filename-$(date +%F-%T)
PS: use -r for zip to avoid zipping and empty directories
scp command
Linux Commands
The scp is a command-line utility that allows you to copy files and directories from one server to another
Copy a file or a directory from a remote server to your local machine (download)
scp -r [username]@[server IP address or domain name]:[remote path] [destination path]
scp -r tia@server4.anomicatech.com:/tmp/devops /home/tia/Download/devops-course
scp -r tia@server4.anomicatech.com:/tmp/devops .
Copy a file or a directory from local to a remote server (upload)
scp -r [directory name or path] [username]@[server IP address]:[destination path][directory name]
scp -r ~/Download/devops-course tia@server4.anomicatech.com:/tmp/devops
scp -r devops-course tia@server4.anomicatech.com:/tmp/devops
Copy all directories and files from a remote server
scp -r tia@server4.anomicatech.com:/tmp/* /home/tia/Download/devops-course
scp -r tia@server4.anomicatech.com:/tmp/* .
vimdiff , dif and alias
Linux Commands
The vimdiff is a command-line utility that allows you to compare two files line by line.
Example : # vimdiff [file1] [file2]
The alias command is like custom shortcuts used to represent a command (or set of commands) executed with or without custom options
Example : # alias [alias_name]=[command]
# alias c="clear"
The diff is a command-line utility that allows you to compare two files
Example : # diff [file1] [file2]
vim ~/.bashrc
source ~/.bashrc
alias c='clear'
alias u='uname -a'
alias g='git'
free , df and du
Linux Commands
The free command provides information about the total amount of the physical and swap memory, as well as the free and used memory.
Example : # free
The df (short for disk free) is used to show the amount of free disk space available on Linux
Example : # df
The du command stand for disk usage, is used to estimate file space usage
Example : # du
# du -sh tia-devops
Options:
free , df and du
Linux Commands
The top command is used to check all current running processes in Linux.
ps: to exit the top command, press q in your keyboard
Example : # top
The ps command is used to check all current running processes in Linux.
Example : # ps
The kill command is used to kill or terminate a process in Linux.
Example : # kill -9 [process_id]
The uptime command is used to check how long the system has been up.
Example : # uptime
Options:
kill -9 = Kill the parent and the children processes at once
kill -15 = Kill the children processes before killing the parent process (soft kill)
Package manager in Linux
Student1@
apt and yum
Package Manager In Linux
apt command in Linux is used to install and delete package in Ubuntu or Debian operating system
Example : # apt install -y [package name]
# apt-get install -y [package name]
# apt remove -y [package name]
yum command in Linux is used to install and delete package in CentOS or RedHat operating system
Example : # yum install -y [package name]
# yum remove -y [package name]
The which command is used to identify the location of a given executable that is executed when you type the executable name (command) in the terminal prompt.
Example : # which [command name or package name]
Options:
Student1@
service and systemctl
Service In Linux
The systemctl command is used manage services or daemons in Linux.
Example : # systemctl start [package name]
# systemctl stop [package name]
# systemctl status [package name]
# systemctl restart [package name]
# systemctl enable [package name]
The service command is used manage services or daemons in Linux.
Example : # service [package name] start
# service [package name] stop
# service [package name] status
# service [package name] restart
# service [package name] enable
A process is simply an application or a script which can be running in the foreground or the background. Service or systemctl is a command which allows you start, stop or restart services running in the background
Student1@
service and systemctl
Service In Linux
The systemctl command is used manage services or daemons in Linux.
Example : # systemctl start [package name]
# systemctl stop [package name]
# systemctl status [package name]
# systemctl restart [package name]
# systemctl enable [package name]
The service command is used manage services or daemons in Linux.
Example : # service [package name] start
# service [package name] stop
# service [package name] status
# service [package name] restart
# service [package name] enable
apt update -y
apt install wget -y
apt install unzip -y
apt install apache2 -y
cd /var/www/html/
wget https://linux-devops-course.s3.amazonaws.com/WEB+SIDE+HTML/covid19.zip
unzip covid19.zip
cp -R covid19/* .
rm -rf covid19.zip
rm -rf covid19
systemctl start apache2
systemctl status apache2
systemctl enable apache2
wget https://linux-devops-course.s3.amazonaws.com/articles.zip
unzip articles.zip
cp -R articles/* .
rm -rf articles.zip
rm -rf articles
Vim Editor in Linux
Student1@
vim
Vim In Linux
The vim command is used to edit or add contain into files, vim can also help create a file that does not exist yet and add content inside.
We have 3 mode in vim:
How to open or create a file in vim?
Example : # vim [file_name]
How to install vim?
Example : # yum install vim -y or apt install vim
Student1@
vim
Vim In Linux
Options:
Options:
Options:
Users and Groups Management
useradd , userdel, id, groups and passwd
User and Group Management
The useradd command is used to create a new user account in Linux
Example : # useradd [user_name]
The userdel is used to delete users in Linux
Example : # userdel [user_name]
The id command is a command-line utility that prints the real and effective user and group IDs
Example : # id [user_name]
The groups command is used to check the group that the user belongs to in Linux
Example : # groups [user_name]
The passwd command is used assign or reset a user account password in Linux
Example : # groups [user_name]
Options:
groupadd and groupdel
The groupadd command is used to creates a new group in Linux
Example : # groupadd [group_name]
# groupadd sysadmin
# groupadd finance; groupadd HR; groupadd manager
The groupdel command is used to delete a existing group in Linux.
PS: This will delete all members of the group.
Example : # groupdel [group_name]
# groupdel sysadmin
# groupdel finance; groupadd HR; groupadd manager
Options: None
User and Group Management
groupadd and groupdel
The usermod command is a command in Linux that is used to change the properties of a user in Linux through the command line or to modify a user account
Example : # usermod [options] [user_name]
Options:
usermod -aG [group_name] [username] = Add a user to a secondary group or supplementary group
usermod -s /sbin/nologin [username] = Modify a user default shell
usermod -L = Lock a user account
usermod -U = Unlock a user account
usermod -l (new username + old username) = Change the login name
usermod -c (usermod -c "Tom Smith" tom) = Add a full name or comment
usermod -s /sbin/nologin -aG manager,finance,sysadmin -c "Tim Smith" tim
Options:
User and Group Management
Student1@
sudo
User and Group Management
The sudo command is used to allow a permitted user to execute a command as the superuser (root)
Example : # sudo [command]
The visudo command is used to to open the sudoers file
Example : # visudo
# sudo -i
username ALL=(ALL:ALL) NOPASSWD:ALL = This user will run all commands as root without a sudo password
%group_name ALL=(ALL:ALL) ALL NOPASSWD:ALL = All users in this group will run all commands as root without a sudo password
username ALL=(ALL:ALL) ALL = This user will run all commands as root with a sudo password
%group_name ALL=(ALL:ALL) ALL = All users in this group will run all commands as root with a sudo password
PS: do not use vim to open or edit the sudoers file (It will locked the system) === >> vim /etc/sudoers
How to change the default sudo timeout?
sudo visudo
Defaults:USER timestamp_timeout=30
Defaults:USER timestamp_timeout=0
The default is 5 minutes
Defaults timestamp_timeout=30
Student1@
passwd and chage
User and Group Management
The passwd command is used to create or update existing passwords of users
Example : # passwd [user_name]
# passwd --expire [user_name] = expire a user password
# passwd -e [user_name] = expire a user password
# passwd -e [user_name] = expire a user password
# chage -l [user_name] = check if the user password is expired
# passwd -S [user_name] = check if the user password is locked
# passwd -S tom
tom L 08/15/2022 0 99999 7 -1 (L means the Password locked.)
tom P 08/15/2022 0 99999 7 -1: it is unlock (P means the Password locked.)
If the password starts with ! in /etc/shadow, the account is locked
passwd -l [user_name]= lock the user account
passwd -u [user_name] = unlock the user account
usermod -L [user_name] = lock the user account
usermod -U [user_name] = unlock the user account
Linux File and Directories Permission
Student1@
File and directory permissions
Student1@
File and directory permissions
Ownership of Linux files
Every file and directory on your Unix/Linux system is assigned 3 types of the owner, as given below.
Student1@
File and directory permissions
Permissions
Every file and directory in your UNIX/Linux system has following 3 permissions defined for all the 3 owners discussed above.
Student1@
File and directory permissions
Changing file/directory permissions with 'chmod' command
Syntax:
chmod [permissions] [file/directory name]
There are 2 ways to use the command
This is what you will used the a lot in the real world
chmod [scrpt_name]
Student1@
File and directory permissions
Student1@
File and directory permissions
Student1@
File and directory permissions
Student1@
File and directory permissions
Crontab in Linux
Student1@
Crontab or Cron Job
Cron Job
To schedule a crontab
crontab -e
List a cron jobs
crontab -l
To delete a cron job
crontab -r
Student1@
Crontab or Cron Job
Cron Job
To schedule a crontab
crontab -e
List a cron jobs
crontab -l
To delete a cron job
crontab -r
Student1@
Crontab or Cron Job
Schedule a cron to execute on every 10 minutes.
If you want to run your script on a 10 minutes interval, you can configure it like below. These types of crons are useful for monitoring.
*/10 * * * * sh /scripts/monitor.sh
Schedule a cron to execute every minute.
Generally, we don’t require any script to execute every minute but in some cases, you may need to configure it.
* * * * * sh /scripts/script.sh
This will echo Hello every minutes
* * * * * echo "Hello" >> /tmp/test.txt
crontab -e
crontab -r
Schedule tasks to execute on Weekly ( @weekly ).
@weekly timestamp is similar to 0 0 1 * mon. It will execute a task in the first minute of the week. It may be useful to do weekly tasks like the cleanup of the system etc.
@weekly sh /bin/script.sh
Schedule tasks to execute on hourly ( @hourly ).
@hourly timestamp is similar to 0 * * * *. It will execute a task in the first minute of every hour, It may be useful to do hourly tasks.
@hourly sh /scripts/script.sh
crontab -e
* * * * * rm -rf /tmp/*
Advance Commands in Linux
Student1@
Advance Command Linux
The cut command is a command-line utility for cutting sections from each line of a file. It writes the result to the standard output. It can be used to cut parts of a line by delimiter, position, and character
The pipe command takes the output of command and send it as input to another command.
Example : # cut [option] [file]
# head -n10 /etc/passwd | cut -d: -f1-3
# uname -a | cut -d" " -f3 | cut -d- -f1 | cut -d. -f1-2
# cat /etc/*release |grep DISTRIB_ID |cut -d= -f2
# cut -d: -f1-3 /etc/passwd
# head -n10 /etc/passwd | cut -d: -f1-7
The grep (Global Regular Expression) command is used to search for a particular string or word in the file
Options:
cut, grep and pipe
Student1@
The grep (Global Regular Expression) command is used to search for a particular string or word in the file
Options:
The awk command is a command-line utility for cutting sections from each line of a file. It writes the result to the standard output. It can be used to cut parts of a line by delimiter, position, and character.
The pipe command takes the output of command and send it as input to another command.
Example : # awk [option] [file]
# free -h |grep "Mem:" |awk '{print$2}'
# lscpu |grep "CPU MHz:" |awk '{print$3}' |awk -F. '{print$1}'
# df -mh |grep "/dev/" |head -1 |awk '{print$5}' |awk -F% '{print$1}'
# cat /etc/ssh/sshd_config |grep -i ^PasswordAuthentication |awk '{print$2}'
# ls -l |awk -F" " '{print$9}'
# ifconfig |grep netmask |head -1 |awk -F" " '{print$2}'
# netstat -ano |grep 22 |head -1 |awk -F" " '{print$4}' |awk -F: '{print$2}'
# cat /etc/*release |grep DISTRIB_DESCRIPTION |awk -F'="' '{print$2}' |awk -F" " '{print$1}'
awk, grep and pipe
Advance Command Linux
Student1@
sed, grep and pipe
The sed command in UNIX stands for stream editor and it can perform a lot of functions on files like searching, finding and replacing, insertion or deletion.
The pipe command takes the output of command and send it as input to another command.
Example :
# sed -i '/^%admin/d' /etc/sudoers
# sed -i '/ALL=(ALL:ALL) ALL/a%admin ALL=(ALL) ALL' /etc/sudoers
sed -i '/# Allow members of group sudo to execute any command/a%admin ALL=(ALL) ALL' sudoers
sed -i '/^s4tia/d' sudoers
sed -i '/^%admin/d' sudoers
sed -i '/# User privilege specification/as4tia ALL=(ALL) ALL' sudoers
sed -i '/# User privilege specification/a%admin ALL=(ALL) ALL' sudoers
# cat /etc/ssh/sshd_config |grep -i ^PasswordAuthentication |awk '{print$2}'
# sed -i '/PasswordAuthentication no/d' sshd_config
# sed -i '/PasswordAuthentication yes' sshd_config
The grep (Global Regular Expression) command is used to search for a particular string or word in the file
Options:
Advance Command Linux
find, reboot and shutdown
Linux Commands
The find command is used to filter objects (files and directories) in the file system
Example : # find [where to start searching from] [-options] [what to find]
find / -iname [file name]
find / -iname [directory name]
find / -type f -iname [file name]
find / -type d -iname [directory name]
find . -iname tecmint.txt
The reboot command is used to reboot or restart the system
Example : # reboot
The shutdown command is used to restart or shutdown the system
Example : # reboot
shutdown -h +5 "Server is going down for upgrade. Please save your work."
shutdown -h + number of minute + [message]
shutdown -h +10 "Server is going down for upgrade. Please save your work."
shutdown -r +5 "Server will restart in 5 minutes. Please save your work."
-r = restart
-h = shutdown
reboot and init 6 = restart
init 0, halt, poweroff = stop the system
Links
Student1@
Links
Practice directory
Linux Commands
relative path and absolute path in linux
Student1@
Congratulations