Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
The Linux DevOps Handbook

You're reading from  The Linux DevOps Handbook

Product type Book
Published in Nov 2023
Publisher Packt
ISBN-13 9781803245669
Pages 428 pages
Edition 1st Edition
Languages
Concepts
Authors (2):
Damian Wojsław Damian Wojsław
Profile icon Damian Wojsław
Grzegorz Adamowicz Grzegorz Adamowicz
Profile icon Grzegorz Adamowicz
View More author details

Table of Contents (20) Chapters

Preface 1. Part 1: Linux Basics
2. Chapter 1: Choosing the Right Linux Distribution 3. Chapter 2: Command-Line Basics 4. Chapter 3: Intermediate Linux 5. Chapter 4: Automating with Shell Scripts 6. Part 2: Your Day-to-Day DevOps Tools
7. Chapter 5: Managing Services in Linux 8. Chapter 6: Networking in Linux 9. Chapter 7: Git, Your Doorway to DevOps 10. Chapter 8: Docker Basics 11. Chapter 9: A Deep Dive into Docker 12. Part 3: DevOps Cloud Toolkit
13. Chapter 10: Monitoring, Tracing, and Distributed Logging 14. Chapter 11: Using Ansible for Configuration as Code 15. Chapter 12: Leveraging Infrastructure as Code 16. Chapter 13: CI/CD with Terraform, GitHub, and Atlantis 17. Chapter 14: Avoiding Pitfalls in DevOps 18. Index 19. Other Books You May Enjoy

Intermediate Linux

In this chapter, we’re going to continue with the introduction to the Linux shell. The topic itself is vast and warrants a book of its own. We will be coming back to the topics from the previous chapter and introducing new ones.

In this chapter, we will cover the following topics:

  • Globs
  • Automating repetitive tasks
  • Software installation
  • Managing users
  • Secure Shell (SSH) protocol

Technical requirements

It is highly recommended that you have a Linux system installed and ready for use. We recommend it be a virtual machine or a laptop that you can safely reinstall from scratch in case something goes horribly wrong. This will let you follow the examples in this book and perform any kind of exercise that we give you.

We are not going to cover an installation. Every distribution may use its own installer, be it graphical or text (depending on the distribution and which variant you’ve picked). You’ll need to note down or remember the name of your user (conveniently called username or login) and password. There are ways to get into the system if you have physical access and you don’t know either the login or password or both, but they are way outside the scope of this book.

Our main distribution in this book is Debian. However, you should be okay with any of the major ones we covered in the previous chapter, so long as it isn’t Alpine...

Globs

There is a lot that a shell can do for you to make your life easier. One of them is allowing for a level of uncertainty when typing in arguments on the shell. To that end, the shell defines several special characters that are treated like symbols for something, not like literal input. These are called global patterns, or globs. The characters that are used in globs are sometimes referred to as wildcards.

Do not confuse globs with regular expressions (regexps). While globs are quite a powerful tool on their own, they are no match for regexps. On the other hand, regexps are not evaluated by bash when it performs pattern matching.

The following table describes shell globs and their meaning. We’re going to explain their exact meaning through several examples:

...

Automating repetitive tasks

There are times when you’ll want to make some tasks repetitive. You may write a script that will create a backup of a database, check users’ home directory permissions, or dump current operating system preformance metrics into a file. Modern Linux distributions provide you with two ways of setting these up. There is a third method that allows you to run a task once, at a delayed time (the at command), but here, we’re interested in repetitive tasks.

Cron jobs

Cron is a traditional way of running tasks that need to be executed regularly at specified intervals. Usually, they should be obsolete by systemd timers, but a lot of software provides repeatability through the use of cron jobs and Alpine Linux won’t have this in the name of the minimal-sized distribution.

Cron jobs are essentially commands that are run at predefined intervals. The command and their trigger timers are defined in configuration files that live in the...

Software installation

Depending on which distribution you’ve chosen and the type of installation you’ve decided on, your system may lack software that’s essential for your everyday work. It may also be that you one day require a piece of software that isn’t installed by default.

Linux distributions pioneered something that other operating systems mirrored later on. The common way of installing software on the Linux operating system is by running an appropriate command that will fetch a binary, put it properly on the system, add some configuration if required, and make it available to users. Today, this may not sound revolutionary at all. After all, we’re living in a world of Apple App Store, Google Play, and Microsoft Apps. But back in the day when Windows and macOS users had to navigate the internet to find a suitable installer for their software, Linux users could install most of it with a single command.

This is important in the automated...

Managing users

The user in a Linux system is defined by a set of three files:

  • /etc/passwd: This file contains information about the user – that is, the user’s name, unique numerical ID (UID) in the system, the primary group the user belongs to GID, the path to the home directory, and the shell that is loaded when the user logs in. A typical entry looks like this:
   admin:x:1000:1000:Debian:/home/admin:/bin/bash

Each line describes exactly one user. Fields are separated by a colon. The second field will only contain anything other than x in very exotic cases. Here, x means that the password is stored separately in the /etc/shadow file. The reason is that permissions for the /etc/passwd file have to be a bit more relaxed so that the login process can work. /etc/shadow can only be read by root and root group and written to only by root:

    root@myhome:~# ls -ahl /etc/passwd
    -rw-r--r-- 1 root...

Secure Shell (SSH) protocol

In the DevOps world, almost nothing runs locally on your laptop or PC. There is one golden standard among ways to reach remote systems and it’s the SSH protocol. SSH was developed in 1995 as a secure, encrypted remote shell access tool that would replace plaintext utilities such as telnet or rsh. The main reason for this is that in distributed networks, it is too easy to eavesdrop on communication and anything that is being transmitted in open text can easily be intercepted. This includes important data such as login details.

The most commonly used SSH server (and the client) in the Linux world is OpenSSH (https://www.openssh.com/). Other open source servers that are still maintained at the time of writing are lsh (http://www.lysator.liu.se/~nisse/lsh/), wolfSSH (https://www.wolfssl.com/products/wolfssh/), and Dropbear (https://matt.ucc.asn.au/dropbear/dropbear.html).

SSH is mainly used to log into a remote machine to execute commands. But it...

Summary

This chapter concludes our introduction to the basic Linux operations you will need in your daily work. It has by no means been comprehensive enough to explain everything that you need to know to manage your Linux system, but it is enough to get you started and should be enough to help you manage your system. In the next chapter, we are going to cover writing shell scripts from the very beginning and guide you through basic and more advanced topics.

Exercises

Try out the following exercises to test your knowledge of this chapter:

  1. In Debian/Ubuntu, install the vim package.
  2. Create a cron job that will create a file called /tmp/cronfile every Saturday at 10:00 A.M.
  3. Create a group called admins and add an existing user to it.
lock icon The rest of the chapter is locked
You have been reading a chapter from
The Linux DevOps Handbook
Published in: Nov 2023 Publisher: Packt ISBN-13: 9781803245669
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}

Glob

Meaning

*

Matches any number of any characters (also zero)