Mastering Ubuntu Server - Third Edition

Book description

This is the third edition of the bestselling one-stop resource for sysadmins and DevOps professionals to learn, configure and use Ubuntu 20.04 for their day-to-day operations and deployments.

Key Features

  • A hands-on book that will teach you how to deploy, maintain and troubleshoot Ubuntu Server
  • Learn to leverage the improved performance and security-related aspects of Ubuntu Server 20.04 LTS
  • New chapters dedicated to exploring Ubuntu for cloud

Book Description

Ubuntu Server has taken data centers around the world by storm. Whether you're deploying Ubuntu for a large-scale project or for a small office, it is a stable, customizable, and powerful Linux distribution with innovative and cutting-edge features. For both simple and complex server deployments, Ubuntu's flexible nature can be easily adapted to meet to the needs of your organization.

This third edition is updated to cover the advancements of Ubuntu 20.04 LTS and further train you to understand how to use Ubuntu Server, from initial deployment to creating production-ready resources for your network. The book begins with the concepts of user management, group management, and file system permissions. Continuing into managing storage volumes, you will learn how to format storage devices, utilize logical volume management, and monitor disk usage. Later, you will learn how to virtualize hosts and applications, which will include setting up QEMU & KVM, as well as containerization with both Docker and LXD. As the book continues, you will learn how to automate configuration with Ansible, as well as take a look at writing scripts. Lastly, you will explore best practices and troubleshooting techniques when working with Ubuntu Server that are applicable to real-world scenarios.

By the end of this Ubuntu Server book, you will be well-versed in Ubuntu server's advanced concepts and attain the required proficiency needed for Ubuntu Server administration.

What you will learn

  • Manage users, groups, and permissions
  • Optimize the performance of system resources
  • Perform disk encryption and decryption with Linux Unified Key Setup (LUKS)
  • Set up Secure Shell (SSH) for remote access, and connect it to other nodes
  • Share directories using Samba and Network File System (NFS)
  • Get familiar with scripting to improve command-line efficiency
  • Configure VMs, containers, and orchestrate with MicroK8s and Kubernetes
  • Automate server deployments with Ansible and cloud server deployments with Terraform

Who this book is for

The book is written to cater to sysadmins and DevOps professionals whose teams are planning to employ an Ubuntu/Linux environment for their development needs.

Prior knowledge of Ubuntu is not required. However, it is assumed that you possess some IT admin, Linux, and shell scripting experience.

Table of contents

  1. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Get in touch
  2. Deploying Ubuntu Server
    1. Technical requirements
    2. Determining your server's role
    3. Setting up our server
      1. Virtual machine
      2. Physical server
      3. Virtual private server
      4. Spare desktop or laptop
      5. Raspberry Pi
    4. Obtaining installation media
    5. Creating a bootable flash drive
      1. Planning the partitioning layout
    6. Installing Ubuntu Server
      1. Installing media
      2. Customizing the installation
      3. Configuring the server's disk
      4. Creating the initial user account
    7. Installing Ubuntu on a Raspberry Pi
    8. Summary
    9. Further Reading
  3. Managing Users and Permissions
    1. Understanding users and groups
    2. Understanding when to use root
      1. Using sudo to run privileged commands
    3. Creating and removing users
      1. Using useradd
      2. Using adduser
      3. Removing users
    4. Understanding the /etc/passwd and /etc/shadow files
      1. Using /etc/passwd
      2. Using /etc/shadow
    5. Distributing default configuration files with /etc/skel
    6. Switching users
    7. Managing groups
    8. Managing passwords and password policies
      1. Locking and unlocking user accounts
      2. Setting password expiration information
      3. Setting a password policy
    9. Configuring administrator access with sudo
    10. Setting permissions on files and directories
      1. Viewing permissions
      2. Changing permissions
      3. Changing the ownership of objects
    11. Summary
    12. Further reading
  4. Managing Software Packages
    1. Understanding Linux package management
    2. Understanding the differences between Debian and Snap packages
      1. Debian packages
      2. Snap packages
    3. Installing and removing software
      1. Managing Debian packages with apt
      2. Managing Snap packages with snap
    4. Searching for packages
    5. Managing package repositories
      1. Adding additional repositories
      2. Adding Personal Package Archives
    6. Backing up and restoring Debian packages
    7. Cleaning up orphaned apt packages
    8. Taking advantage of hardware enablement updates
    9. Summary
    10. Further reading
  5. Navigating and Essential Commands
    1. Learning essential Linux commands
    2. Understanding the Linux filesystem layout
    3. Viewing the contents of files
    4. Viewing application log files
    5. Summary
    6. Further reading
  6. Managing Files and Directories
    1. Copying, moving, and renaming files and directories
    2. Editing files with the Nano and Vim text editors
      1. Editing with Nano
      2. Editing with Vim
    3. Input and output streams
    4. Using symbolic and hard links
    5. Summary
    6. Further reading
  7. Boosting Your Command-line Efficiency
    1. Understanding the Linux shell
    2. Understanding Bash history
    3. Learning some useful command-line tricks
    4. Understanding variables
    5. Writing simple scripts
    6. Putting it all together – Writing an rsync backup script
    7. Summary
    8. Further reading
  8. Controlling and Managing Processes
    1. Managing jobs
    2. Understanding the ps command
      1. Viewing running processes with ps
      2. Configuring arguments to ps
    3. Changing the priority of processes
    4. Dealing with misbehaving processes
    5. Managing system processes
    6. Scheduling tasks with cron
    7. Summary
    8. Further reading
  9. Monitoring System Resources
    1. Viewing disk usage
      1. Using df
      2. Diving deeper into disk usage
    2. Monitoring memory usage
      1. Understanding server memory
      2. Managing swap
    3. Understanding load average
    4. Viewing resource usage with htop
    5. Summary
    6. Further reading
  10. Managing Storage Volumes
    1. Adding additional storage volumes
    2. Formatting and partitioning storage devices
      1. Creating a partition
      2. Formatting partitions
    3. Mounting and unmounting volumes
    4. Understanding the /etc/fstab file
      1. Analyzing the contents of /etc/fstab
      2. Adding to the /etc/fstab file
    5. Backing up and restoring volumes
    6. Utilizing LVM
      1. Getting started with LVM
      2. Formatting logical volumes
      3. Removing volumes with LVM
      4. Understanding LVM snapshots
    7. Summary
    8. Further reading
  11. Connecting to Networks
    1. Setting the hostname
    2. Managing network interfaces
    3. Assigning static IP addresses
    4. Understanding Linux name resolution
    5. Getting started with OpenSSH
      1. Installing OpenSSH
      2. Issuing commands with OpenSSH
    6. Getting started with SSH key management
      1. Generating public and private keys
      2. Copying your public key to a remote server
      3. Utilizing an SSH agent
      4. Changing the passphrase of an OpenSSH key
    7. Simplifying SSH connections with a config file
    8. Summary
    9. Further reading
  12. Setting Up Network Services
    1. Planning your IP address scheme
    2. Setting up a DHCP server for serving IP addresses
    3. Adding a DNS server
      1. Setting up external DNS with bind
      2. Setting up internal DNS and adding hosts
    4. Setting up an internet gateway
    5. Keeping your clock in sync with NTP
    6. Summary
    7. Further reading
  13. Sharing and Transferring Files
    1. File server considerations
    2. Sharing files with Windows users via Samba
    3. Setting up NFS shares
    4. Transferring files with rsync
    5. Transferring files with SCP
    6. Mounting remote directories with SSHFS
    7. Summary
    8. Further reading
  14. Managing Databases
    1. Preparations for setting up a database server
    2. Installing MariaDB
    3. Understanding the MariaDB configuration files
    4. Managing MariaDB databases
    5. Setting up a secondary database server
    6. Summary
    7. Further reading
  15. Serving Web Content
    1. Installing and configuring Apache
    2. Installing additional Apache modules
    3. Securing Apache with TLS
    4. Installing and configuring NGINX
    5. Setting up failover with keepalived
    6. Setting up and configuring Nextcloud
    7. Summary
    8. Further reading
  16. Automating Server Configuration with Ansible
    1. Understanding the need for configuration management
    2. Why Ansible?
    3. Creating a Git repository
    4. Getting started with Ansible
    5. Making your servers do your bidding
      1. Setting up an inventory file and configuring Ansible settings
      2. Configuring client servers
    6. Putting it all together – automating web server deployment
    7. Using Ansible's pull method
    8. Summary
    9. Further reading
  17. Virtualization
    1. Prerequisites and considerations
    2. Setting up a virtual machine server
    3. Creating virtual machines
    4. Bridging the virtual machine network
    5. Simplifying virtual machine creation with cloning
    6. Managing virtual machines via the command line
    7. Summary
    8. Further reading
  18. Running Containers
    1. What is containerization?
    2. Understanding the differences between Docker and LXD
    3. Installing Docker
    4. Managing Docker containers
    5. Automating Docker image creation with Dockerfiles
    6. Managing LXD containers
    7. Summary
    8. Further reading
  19. Container Orchestration
    1. Container orchestration
    2. Preparing a lab environment for Kubernetes testing
    3. Utilizing MicroK8s
      1. Installing MicroK8s on Linux
      2. Installing MicroK8s on macOS
      3. Installing MicroK8s on Windows
      4. Interacting with MicroK8s
    4. Setting up a Kubernetes cluster
      1. Configuring Docker
      2. Testing Docker
      3. Installing Kubernetes
    5. Deploying containers via Kubernetes
    6. Summary
    7. Further reading
  20. Deploying Ubuntu in the Cloud
    1. Understanding the difference between on-premises and cloud infrastructure
    2. Important considerations when considering cloud computing as a potential solution
    3. Becoming familiar with some basic AWS concepts
    4. Creating an AWS account
      1. Signing up for AWS
      2. Implementing basic user security
    5. Choosing a region
    6. Deploying Ubuntu as an AWS EC2 instance
      1. Setting up an IAM Role for Session Manager
      2. Creating an Ubuntu Server instance in AWS
    7. Creating and deploying Ubuntu AMI images
    8. Automatically scaling Ubuntu EC2 deployments with Auto Scaling
      1. Creating a launch template
      2. Creating an Auto Scaling group
      3. Creating a load balancer
    9. Keeping costs down: understanding how to save money and make cost-effective decisions
      1. Viewing billing information
      2. Adding a billing alert
      3. Removing unneeded backups
      4. Running EC2 instances only when they're needed
      5. Stopping or terminating unneeded EC2 instances
    10. Taking cloud further: additional resources to grow your knowledge
      1. Online training and labs
      2. Certification
      3. Keep experimenting and learning
      4. AWS documentation
    11. Summary
    12. Further reading
  21. Automating Cloud Deployments with Terraform
    1. Why it's important to automate your infrastructure
    2. Introduction to Terraform and how it can fit within your workflow
    3. Installing Terraform
    4. Automating an EC2 instance deployment
    5. Managing security groups with Terraform
    6. Using Terraform to destroy unused resources
    7. Combining Ansible with Terraform for a full deployment solution
    8. Summary
  22. Securing Your Server
    1. Lowering your attack surface
    2. Understanding and responding to CVEs
    3. Installing security updates
    4. Automatically installing patches with the Canonical Livepatch service
    5. Monitoring Ubuntu servers with Canonical's Landscape service
    6. Securing OpenSSH
    7. Installing and configuring Fail2ban
    8. MariaDB best practices for secure database servers
    9. Setting up a firewall
    10. Encrypting and decrypting disks with LUKS
    11. Locking down sudo
    12. Summary
    13. Further reading
  23. Troubleshooting Ubuntu Servers
    1. Evaluating the scope
    2. Conducting a root cause analysis
    3. Viewing system logs
    4. Tracing network issues
    5. Troubleshooting resource issues
    6. Diagnosing defective RAM
    7. Summary
    8. Further reading
  24. Preventing Disasters
    1. Preventing disasters
    2. Utilizing Git for configuration management
    3. Implementing a backup plan
    4. Replacing failed RAID disks
    5. Utilizing bootable recovery media
    6. Summary
    7. Further reading
  25. Another Book You May Enjoy
  26. Index

Product information

  • Title: Mastering Ubuntu Server - Third Edition
  • Author(s): Jay LaCroix
  • Release date: December 2020
  • Publisher(s): Packt Publishing
  • ISBN: 9781800564640