Linux for DevOps

Linux for DevOps

Along with 50 most frequently used commands and examples.

Linux has been a popular operating system for decades, especially among developers and system administrators. With its flexibility and powerful command-line interface, Linux is a natural choice for those working in the field of DevOps. In this blog, we'll explore the topic of Complete Linux for DevOps and some essential commands that every DevOps professional should know.

What is DevOps?

Before we dive into Linux commands, let's briefly discuss DevOps. DevOps is a set of practices that combines software development (Dev) and IT operations (Ops) to shorten the systems development life cycle and deliver software more quickly and reliably. DevOps aims to break down the silos between development and operations teams and encourage collaboration and communication between the two.

DevOps involves a lot of automation and continuous integration/continuous deployment (CI/CD) practices. To implement these practices effectively, DevOps professionals need a powerful and flexible operating system that can handle complex tasks with ease. Linux is an excellent choice for this purpose.

What is Linux?

Just like Windows, iOS, and Mac OS, Linux is an operating system. One of the most popular platforms on the planet, Android, is powered by the Linux operating system. An operating system is software that manages all of the hardware resources associated with your desktop or laptop. The operating system manages the communication between your software and your hardware. Without the operating system (OS), the software wouldn’t function.

The Linux operating system comprises several different pieces:

  1. Bootloader – The software that manages the boot process of your computer. For most users, this will simply be a splash screen that pops up and eventually goes away to boot into the operating system.

  2. Kernel – This is the one piece of the whole that is called ‘Linux’. The kernel is the core of the system and manages the CPU, memory, and peripheral devices. The kernel is the lowest level of the OS.

  3. Init system – This is a sub-system that bootstraps the user space and is charged with controlling daemons. One of the most widely used init systems is systemd, which also happens to be one of the most controversial. It is the init system that manages the boot process, once the initial booting is handed over from the bootloader (i.e., GRUB or GRand Unified Bootloader).

  4. Daemons – These are background services (printing, sound, scheduling, etc.) that either start up during boot or after you log into the desktop.

  5. Graphical server – This is the sub-system that displays the graphics on your monitor. It is commonly referred to as the X server or just X.

  6. Desktop environment – This is the piece that the users actually interact with. There are many desktop environments to choose from (GNOME, Cinnamon, Mate, Pantheon, Enlightenment, KDE, Xfce, etc.). Each desktop environment includes built-in applications (such as file managers, configuration tools, web browsers, and games).

  7. Applications – Desktop environments do not offer the full array of apps. Just like Windows and macOS, Linux offers thousands upon thousands of high-quality software titles that can be easily found and installed. Most modern Linux distributions (more on this below) include App Store-like tools that centralize and simplify application

Some of the key features of Linux:

  1. Open Source: Linux is an open-source operating system, which means that its source code is freely available to anyone who wants to use, modify, or redistribute it. This allows developers and users to customize the operating system to meet their specific needs.

  2. Stability: Linux is known for its stability and reliability. It can run for weeks or even months without needing a reboot, making it ideal for servers and other mission-critical applications.

  3. Security: Linux is inherently more secure than other operating systems because of its architecture and the way it handles permissions. It has a robust security model that makes it difficult for viruses and malware to infect the system.

  4. Flexibility: Linux is highly flexible and customizable. It can be tailored to meet the specific needs of individual users and organizations, whether it's through the use of different desktop environments or custom software configurations.

  5. Command-line interface: Linux is known for its powerful command-line interface, which allows users to perform a wide range of tasks quickly and efficiently. This is particularly useful for DevOps professionals who need to automate repetitive tasks and perform complex system administration tasks.

  6. Compatibility: Linux is compatible with a wide range of hardware platforms, including desktops, servers, mobile devices, and embedded systems. This makes it a versatile operating system that can be used in a variety of applications and environments.

  7. Community: Linux has a large and active community of developers and users who contribute to the development and improvement of the operating system. This means that there is a wealth of resources and support available to users, including online forums, documentation, and tutorials.

What is a Kernel?

The kernel is a central component of the Linux operating system. It is the core part of the operating system that manages system resources and provides a foundation for all other software to run on top of it.

The kernel acts as an intermediary between the computer hardware and the software that runs on it. It provides a set of services and interfaces that software can use to interact with the underlying hardware, including the CPU, memory, storage, and input/output devices.

Some of the key functions of the kernel include:

  1. Memory management: The kernel manages the system's memory, allocating memory to applications as needed and freeing up memory that is no longer in use.

  2. Process management: The kernel manages the system's processes, including starting and stopping them, scheduling them for execution, and allocating system resources to them.

  3. Device management: The kernel manages the system's devices, including input/output devices such as keyboards, mice, and printers, as well as storage devices such as hard drives and USB drives.

  4. Security: The kernel provides a security model that protects the system and its data from unauthorized access and malicious software.

  5. System calls: The kernel provides a set of system calls that allow applications to interact with the kernel and access its services and resources.

What is a Shell?

In the context of Linux and other Unix-based operating systems, a shell is a command-line interface that allows users to interact with the operating system and run various commands and scripts. It is essentially a user interface that provides a way for users to access the operating system's services and resources.

The shell is an application that runs on top of the operating system kernel and provides a way for users to interact with the system. It takes input from the user in the form of commands and then executes those commands by communicating with the kernel.

There are several different shells available for Linux, each with its own set of features and capabilities. The most common shell used in Linux is called Bash (short for Bourne-Again SHell), which is a free and open-source shell that is included with most Linux distributions.

Some of the key features of the shell include:

  1. Command execution: The shell allows users to execute a wide range of commands and scripts, including system commands, utilities, and custom scripts.

  2. Input/output redirection: The shell allows users to redirect input and output to and from files, allowing for more powerful and flexible command execution.

  3. Command history: The shell maintains a history of previously executed commands, making it easy for users to repeat or modify previous commands.

  4. Variables and environment settings: The shell allows users to set and manipulate variables and environment settings, which can be used to customize the behaviour of the shell and other applications.

  5. Scripting: The shell provides a powerful scripting language that allows users to write scripts to automate repetitive tasks and perform complex system administration tasks.

In Linux and other Unix-based operating systems, there are several different types of shells available, each with its own features and capabilities. Some of the most commonly used shells include:

  1. Bash: Bash (short for Bourne-Again SHell) is the most commonly used shell in Linux and is the default shell in most Linux distributions. It provides a wide range of features and capabilities, including command-line editing, command completion, and shell scripting.

  2. Zsh: Zsh (short for Z Shell) is another popular shell that is similar to Bash but includes additional features such as advanced command-line editing, syntax highlighting, and spelling correction.

  3. Fish: Fish (short for Friendly Interactive SHell) is a shell that is designed to be more user-friendly and easier to use than other shells. It includes features such as syntax highlighting, autosuggestions, and a built-in help system.

  4. Ksh: Ksh (short for Korn SHell) is a shell that is compatible with the original Bourne shell and includes additional features such as command-line editing and job control.

  5. Csh: Csh (short for C SHell) is a shell that is designed to be similar to the C programming language and includes features such as aliases and command-line editing.

Essential Linux Commands for DevOps

Now that we've covered the basics of DevOps and Linux, let's dive into some essential Linux commands that every DevOps professional should know.

pwd - The pwd command is used to print the current working directory.
$ pwd
/home/user/Documents
clear - The clear command is used to clear the terminal screen.
$ clear
echo - The echo command is used to display messages on the terminal.
$ echo "Hello, World!"
Hello, World!
sudo - The sudo command is used to run a command with administrative privileges.
$ sudo apt-get update
cd - The cd command is used to change the current directory.
$ cd /home/user/Documents
ls - The ls command is used to list the contents of a directory.
$ ls
file1.txt file2.txt folder1 folder2
cat - The cat command is used to display the contents of a file.
$ cat file1.txt
This is the contents of file1.
less - The less command is used to view a file one page at a time.
$ less file1.txt
grep - The grep command is used to search for a specific pattern in a file.
$ grep "pattern" file1.txt
sort - The sort command is used to sort the contents of a file.
$ sort file1.txt
mv - The mv command is used to move or rename a file.
$ mv file1.txt file2.txt
cp - The cp command is used to copy a file.
$ cp file1.txt file2.txt
rm - The rm command is used to delete a file.
$ rm file1.txt
mkdir - The mkdir command is used to create a new directory.
$ mkdir new_folder
rmdir - The rmdir command is used to delete a directory.
$ rmdir old_folder
chmod - The chmod command is used to change the permissions of a file or directory.
$ chmod 777 file1.txt
chown - The chown command is used to change the owner of a file or directory.
$ chown user file1.txt
tar - The tar command is used to create or extract tar archives.
$ tar -cvf archive.tar file1.txt file2.txt
head - The head command is used to display the first few lines of a file.
$ head file1.txt
id - The id command is used to display the current user's ID and group information.
$ id
man - The man command is used to display the manual page for a command.
$ man ls
df - The df command is used to display disk space usage.
$ df -h
du - The du command is used to display the disk usage of files and directories.
$ du -h file1.txt
ssh - The ssh command is used to connect to a remote server over SSH.
$ ssh user@remote_server
history - The history command is used to display the command history.
$ history
tail - The tail command is used to display the last few lines of a file.
$ tail file1.txt
passwd - The passwd command is used to change the password of the current user.
$ passwd
htop - The htop command is used to monitor system resources in real-time.
$ htop
free - The free command is used to display the amount of free and used memory in the system.
$ free -h
ip - The ip command is used to display network interfaces and their configuration.
$ ip addr show
rpm - The rpm command is used to manage RPM packages.
$ rpm -qa | grep package_name
telnet - The telnet command is used to connect to a remote server over Telnet.
$ telnet remote_server
netstat - The netstat command is used to display network connections, routing tables, and network interface statistics.
$ netstat -a
useradd - The useradd command is used to add a new user account.
$ useradd new_user
userdel - The userdel command is used to delete a user account.
$ userdel old_user
touch - The touch command is used to create a new empty file.
$ touch new_file.txt
awk - The awk command is used to manipulate and process text files.
$ awk '{print $1}' file1.txt
curl - The curl command is used to transfer data to or from a server.
$ curl https://example.com
env - The env command is used to display the current environment variables.
$ env
ps - The ps command is used to display information about running processes.
$ ps aux

User administration in Linux

User administration is an important task in Linux that involves creating, managing and deleting user accounts. This ensures proper access control and security of the system. In Linux, there are several commands and tools that can be used to manage user accounts. Some of the commonly used commands and tools for user administration in Linux are:

useradd - This command is used to create a new user account.
$ sudo useradd new_user
usermod - This command is used to modify an existing user account.
$ sudo usermod -aG sudo new_user
userdel - This command is used to delete an existing user account.
$ sudo userdel old_user
passwd - This command is used to change the password for a user account.
$ sudo passwd new_user
chage - This command is used to set password aging policies for user accounts.
$ sudo chage -M 60 new_user
groupadd - This command is used to create a new user group.
$ sudo groupadd new_group
groupmod - This command is used to modify an existing user group.
$ sudo groupmod -n new_group_name old_group_name
groupdel - This command is used to delete an existing user group.
$ sudo groupdel old_group
id - This command is used to display user and group information.
$ id new_user
su - This command is used to switch to another user account.
$ su new_user
sudo - This command is used to run a command with elevated privileges.
$ sudo apt-get update
visudo - This command is used to edit the sudoers file, which controls sudo access.
$ sudo visudo

If you enjoyed this blog or found it helpful, please give it a heart and leave a comment below to let me know!