Ubuntu Server Cookbook
()
About this ebook
- Master the skills to setup secure and scalable web services with popular tools like Apache, Nginx, MySQL and HAProxy
- Set up your own cloud with Open Stack and quickly deploy applications with Docker or LXD
- Packed with clear, step-by-step recipes to let you protect you valuable data with your own chat servers, code hosting and collaboration tools.
Ubuntu Server Cookbook is intended for system administrators with a basic understanding of Linux operating system. If you are a software developer or a newbie system administrator and want to setup your own servers, this book is an ideal guide for you. You are not required to have an in-depth knowledge or hands-on experience with Ubuntu, but you should know the basic commands for directory navigation, file management, and file editing tool. An understanding of computer networks and Internet is advisable.
Related to Ubuntu Server Cookbook
Related ebooks
CentOS 7 Linux Server Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsOpenVPN Cookbook - Second Edition Rating: 0 out of 5 stars0 ratingsRed Hat Enterprise Linux Server Cookbook Rating: 2 out of 5 stars2/5pfSense 2 Cookbook Rating: 3 out of 5 stars3/5CentOS 7 Server Deployment Cookbook Rating: 0 out of 5 stars0 ratingsGit Version Control Cookbook Rating: 4 out of 5 stars4/5SQL Server 2014 with PowerShell v5 Cookbook Rating: 0 out of 5 stars0 ratingsZabbix Cookbook Rating: 0 out of 5 stars0 ratingsFlask Framework Cookbook Rating: 5 out of 5 stars5/5JavaScript JSON Cookbook Rating: 0 out of 5 stars0 ratingsWindows Server 2012 Automation with PowerShell Cookbook Rating: 0 out of 5 stars0 ratingsSoapUI Cookbook Rating: 0 out of 5 stars0 ratingsWindows Server 2016 Cookbook Rating: 0 out of 5 stars0 ratingsMicrosoft Windows Azure Development Cookbook Rating: 5 out of 5 stars5/5Ubuntu Server Essentials Rating: 0 out of 5 stars0 ratingsLet's Use BASH on Windows 10! Rating: 0 out of 5 stars0 ratingsMastering Ubuntu Server Rating: 5 out of 5 stars5/5Mastering Bash Rating: 5 out of 5 stars5/5Linux Shell Scripting Cookbook - Third Edition Rating: 4 out of 5 stars4/5Mastering CentOS 7 Linux Server Rating: 0 out of 5 stars0 ratingsMastering Linux Shell Scripting Rating: 4 out of 5 stars4/5Learning Windows Server Containers Rating: 0 out of 5 stars0 ratingsInstant Debian - Build a Web Server Rating: 0 out of 5 stars0 ratingsCentOS System Administration Essentials Rating: 0 out of 5 stars0 ratingsImplementing Samba 4 Rating: 0 out of 5 stars0 ratingsLinux Networking Cookbook Rating: 0 out of 5 stars0 ratingsLearn Linux in a Month of Lunches Rating: 3 out of 5 stars3/5Mastering KVM Virtualization Rating: 5 out of 5 stars5/5Linux Commands By Example Rating: 5 out of 5 stars5/5The Linux Command Line Beginner's Guide Rating: 4 out of 5 stars4/5
Operating Systems For You
Windows 11 For Dummies Rating: 0 out of 5 stars0 ratingsExcel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Windows 11 All-in-One For Dummies Rating: 5 out of 5 stars5/5Hacking : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Ethical Hacking Rating: 5 out of 5 stars5/5macOS Big Sur For Dummies Rating: 0 out of 5 stars0 ratingsLinux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Learn Windows PowerShell in a Month of Lunches Rating: 0 out of 5 stars0 ratingsLinux Bible Rating: 0 out of 5 stars0 ratingsWindows Registry Forensics: Advanced Digital Forensic Analysis of the Windows Registry Rating: 4 out of 5 stars4/5Exploring Windows 11: The Illustrated, Practical Guide to Using Microsoft Windows Rating: 0 out of 5 stars0 ratingsLinux Command-Line Tips & Tricks Rating: 0 out of 5 stars0 ratingsMastering Swift 5 - Fifth Edition: Deep dive into the latest edition of the Swift programming language, 5th Edition Rating: 0 out of 5 stars0 ratingsMake Your PC Stable and Fast: What Microsoft Forgot to Tell You Rating: 4 out of 5 stars4/5The Linux Command Line Beginner's Guide Rating: 4 out of 5 stars4/5Mastering macOS Programming Rating: 0 out of 5 stars0 ratingsThe Windows Command Line Beginner's Guide: Second Edition Rating: 4 out of 5 stars4/5Windows 11 For Seniors For Dummies Rating: 0 out of 5 stars0 ratingsUNIX For Dummies Rating: 3 out of 5 stars3/5The Mac Terminal Reference and Scripting Primer Rating: 4 out of 5 stars4/5Mastering Apple MacBook - MacBook Pro, MacBook Air, MacOS Ultimate User Guide Rating: 1 out of 5 stars1/5PowerShell: A Beginner's Guide to Windows PowerShell Rating: 4 out of 5 stars4/5Windows 10 All-In-One For Dummies Rating: 4 out of 5 stars4/5CompTIA Linux+ Study Guide: Exam XK0-004 Rating: 0 out of 5 stars0 ratingsDarknet Rating: 4 out of 5 stars4/5Windows 10 For Dummies Rating: 3 out of 5 stars3/5OneNote: The Ultimate Guide on How to Use Microsoft OneNote for Getting Things Done Rating: 1 out of 5 stars1/5Mac Unlocked: Everything You Need to Know to Get Cracking in macOS Big Sur Rating: 0 out of 5 stars0 ratings
Reviews for Ubuntu Server Cookbook
0 ratings0 reviews
Book preview
Ubuntu Server Cookbook - Uday R. Sawant
Table of Contents
Ubuntu Server Cookbook
Credits
About the Author
www.PacktPub.com
eBooks, discount offers, and more
Why Subscribe?
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Managing Users and Groups
Introduction
Creating a user account
Getting ready
How to do it…
How it works…
There's more…
See also
Creating user accounts in batch mode
Getting ready
How to do it...
How it works…
Creating a group
Getting ready
How to do it...
How it works…
There's more…
See also
Adding group members
Getting ready
How to do it…
How it works…
There's more…
Deleting a user account
Getting ready
How to do it...
How it works…
There's more…
See also
Managing file permissions
Getting ready
How to do it…
How it works…
There's more…
Getting root privileges with sudo
Getting ready
How to do it...
How it works…
There's more…
Setting password less sudo
Other uses of sudo
See also
Setting resource limits with limits.conf
Getting ready
How to do it...
How it works…
There's more…
Setting up public key authentication
Getting ready
How to do it...
How it works…
Working of SSH authentication
There's more…
Troubleshooting SSH connections
SSH tools for the Windows platform
See also
Securing user accounts
How to do it...
How it works…
2. Networking
Introduction
Connecting to a network with a static IP
Getting ready
How to do it…
How it works…
There's more…
IPv6 configuration
See also
Installing the DHCP server
Getting ready
How to do it…
How it works…
There's more…
Installing the DNS server
Getting ready
How to do it…
How it works…
See also
Hiding behind the proxy with squid
Getting ready
How to do it…
How it works…
There's more…
Access control list
Set cache refresh rules
Sarg – tool to analyze squid logs
Squid guard
See also
Being on time with NTP
How to do it…
How it works…
There's more…
See also
Discussing load balancing with HAProxy
Getting ready
How to do it…
How it works…
There's more …
See also
Tuning the TCP stack
Getting ready…
How to do it…
How it works…
See also
Troubleshooting network connectivity
Getting ready
How to do it…
There's more…
Securing remote access with OpenVPN
Getting ready…
How to do it…
How it works…
There's more…
Securing a network with uncomplicated firewall
Getting ready
How to do it…
There's more…
See also
Securing against brute force attacks
Getting ready
How to do it…
How it works…
There's more…
Discussing Ubuntu security best practices
Getting ready
How to do it…
How it works…
See also
3. Working with Web Servers
Introduction
Installing and configuring the Apache web server
Getting ready
How to do it…
How it works…
There's more…
HTTP version 2 support
See also
Serving dynamic contents with PHP
Getting ready
How to do it…
How it works…
PHP settings
There's more…
Installing the LAMP stack
Upgrading PHP under Ubuntu 14
Hosting multiple websites with a virtual domain
Getting ready
How to do it…
How it works…
See also
Securing web traffic with HTTPS
Getting ready
How to do it…
How it works…
There's more…
See also
Installing Nginx with PHP_FPM
Getting ready
How to do it…
How it works…
There's more…
See also
Setting Nginx as a reverse proxy
Getting ready
How to do it…
How it works…
There's more…
HAProxy and Varnish
See also
Load balancing with Nginx
Getting ready
How to do it…
How it works…
There's more…
See also
Setting HTTPs on Nginx
Getting ready
How to do it…
How it works…
See also
Benchmarking and performance tuning of Apache
Getting ready
How to do it…
There's more…
See also
Securing the web server
Getting ready
How to do it…
How it works…
See also
Troubleshooting the web server
Getting ready
How to do it…
Web server not accessible
Virtual host not accessible
Access denied or forbidden errors
Apache downloads .php files
4. Working with Mail Servers
Introduction
Sending e-mails with Postfix
Getting ready
How to do it…
How it works…
See also
Enabling IMAP and POP3 with Dovecot
Getting ready
How to do it…
How it works…
See also
Adding e-mail accounts
Getting ready
How to do it…
How it works…
There's more…
Web console for virtual mailbox administration
See also
Mail filtering with spam-assassin
Getting ready
How to do it…
How it works…
There's more…
See also
Troubleshooting the mail server
Getting ready
How to do it…
See also
Installing the Zimbra mail server
Getting ready
How to do it…
How it works…
There's more…
See also
5. Handling Databases
Introduction
Installing relational databases with MySQL
Getting ready
How to do it…
How it works…
There’s more…
Securing MySQL installation
See also
Storing and retrieving data with MySQL
Getting ready
How to do it…
How it works…
Importing and exporting bulk data
How to do it…
See also
Adding users and assigning access rights
Getting ready
How to do it…
How it works…
There’s more…
Removing user accounts
Setting resource limits
See also
Installing web access for MySQL
Getting ready
How to do it…
How it works…
There’s more…
See also
Setting backups
Getting ready
How to do it…
How it works…
See also
Optimizing MySQL performance – queries
Getting ready
How to do it…
How it works…
There’s more…
Sharding MySQL
See also
Optimizing MySQL performance – configuration
Getting ready
How to do it…
How it works…
There’s more…
Percona configuration wizard
MySQL table compression
See also
Creating MySQL replicas for scaling and high availability
Getting ready
How to do it…
How it works…
There’s more…
See also
Troubleshooting MySQL
Getting ready
How to do it…
See also
Installing MongoDB
Getting ready
How to do it…
How it works…
See also
Storing and retrieving data with MongoDB
Getting ready
How to do it…
How it works…
There’s more…
See also
6. Network Storage
Introduction
Installing the Samba server
Getting ready
How to do it…
How it works…
There's more…
Tools for personal file sharing
See also
Adding users to the Samba server
Getting ready
How to do it…
How it works…
There's more…
See also
Installing the secure FTP server
Getting ready
How to do it…
How it works…
There's more…
See also
Synchronizing files with Rsync
How to do it…
How it works…
There's more…
See also
Performance tuning the Samba server
Getting ready
How to do it…
How it works…
Troubleshooting the Samba server
How to do it…
Checking network connectivity
Checking the Samba service
Checking Samba logs
Checking Samba configuration
See also
Installing the Network File System
Getting ready
How to do it…
How it works…
There's more…
See also
7. Cloud Computing
Introduction
Creating virtual machine with KVM
Getting ready
How to do it…
How it works…
There's more…
See also
Managing virtual machines with virsh
Getting ready
How to do it…
How it works…
There's more…
Easy cloud images with uvtool
See also
Setting up your own cloud with OpenStack
Getting ready
How to do it…
How it works…
There's more…
See also
Adding a cloud image to OpenStack
Getting ready
How to do it…
How it works…
There's more…
See also
Launching a virtual instance with OpenStack
Getting ready
How to do it…
How it works…
There's more…
See also
Installing Juju a service orchestration framework
Getting ready
How to do it…
How it works…
There's more…
See also
Managing services with Juju
Getting ready
How to do it…
How it works…
There's more…
See also
8. Working with Containers
Introduction
Installing LXD, the Linux container daemon
Getting ready
How to do it…
How it works…
There's more…
See also
Deploying your first container with LXD
Getting ready
How to do it…
How it works…
There's more…
See also
Managing LXD containers
Getting ready…
How to do it…
There's more…
See also
Managing LXD containers – advanced options
How to do it…
How it works…
Setting resource limits on LXD containers
How to do it…
How it works…
There's more…
See also
Networking with LXD
Getting ready
How to do it…
How it works…
There's more…
See also
Installing Docker
Getting ready
How to do it…
How it works…
There's more…
See also
Starting and managing Docker containers
Getting ready
How to do it…
How it works…
There's more…
See also
Creating images with a Dockerfile
Getting ready
How to do it…
How it works…
There's more…
See also
Understanding Docker volumes
Getting ready
How to do it…
How it works…
See also
Deploying WordPress using a Docker network
How to do it…
How it works…
There's more…
See also
Monitoring Docker containers
How to do it…
How it works…
There's more…
See also
Securing Docker containers
How to do it…
See also
9. Streaming with Ampache
Introduction
Installing the Ampache server
Getting ready
How to do it…
How it works…
There's more…
See also
Uploading contents and creating catalogs
Getting ready
How to do it…
How it works…
Setting on-the-fly transcoding
Getting ready
How to do it…
Enabling API access for remote streaming
Getting ready
How to do it…
How it works…
Streaming music with Ampache
Getting ready
How to do it…
10. Communication Server with XMPP
Introduction
Installing Ejabberd
Getting ready
How to do it…
How it works…
See also
Creating users and connecting with the XMPP client
Getting ready
How to do it…
How it works…
There's more…
See also
Configuring the Ejabberd installation
Getting ready
How to do it…
How it works…
There's more…
See also
Creating web client with Strophe.js
Getting ready
How to do it…
How it works…
There's more…
See also
Enabling group chat
Getting ready
How to do it…
How it works…
There's more…
See also
Chat server with Node.js
Getting ready
How to do it…
How it works…
There's more…
See also
11. Git Hosting
Introduction
Installing Git
Getting ready
How to do it…
How it works…
There's more…
See also
Creating a local repository with Git CLI
Getting ready
How to do it…
How it works…
There's more…
See also
Storing file revisions with Git commit
Getting ready
How to do it…
How it works…
There's more…
Synchronizing the repository with a remote server
Getting ready
How to do it…
How it works…
There's more…
GitHub pages
See also
Receiving updates with Git pull
Getting ready
How to do it…
How it works…
See also
Creating repository clones
Getting ready
How to do it…
How it works…
See also
Installing GitLab, your own Git hosting
Getting ready
How to do it…
How it works…
There's more…
See also
Adding users to the GitLab server
Getting ready
How to do it…
Creating a repository with GitLab
Getting ready
How to do it…
Automating common tasks with Git hooks
Getting ready
How to do it…
How it works…
See also
12. Collaboration Tools
Introduction
Installing the VNC server
Getting ready
How to do it…
How it works…
See also
Installing Hackpad, a collaborative document editor
Getting ready
How to do it…
How it works…
There's more
Using Hackpad with Docker
See also
Installing Mattermost – a self-hosted slack alternative
Getting ready
How to do it…
How it works…
There's more …
See also
Installing OwnCloud, self-hosted cloud storage
Getting ready
How to do it…
How it works…
See also
13. Performance Monitoring
Introduction
Monitoring the CPU
Getting ready
How to do it…
How it works…
There's more…
See also
Monitoring memory and swap
Getting ready
How to do it…
How it works…
There's more…
See also
Monitoring the network
Getting ready
How to do it…
How it works…
There's more…
Monitoring storage
Getting ready
How to do it…
Setting performance benchmarks
Getting ready
How to do it…
There's more…
Graphing tools
More options
See also
14. Centralized Authentication Service
Introduction
Installing OpenLDAP
Getting ready
How to do it…
How it works…
See also
Installing phpLDAPadmin
Getting ready
How to do it…
How it works…
There's more…
See also
Ubuntu server logins with LDAP
Getting ready
How to do it…
How it works…
See also
Authenticating Ejabberd users with LDAP
Getting ready
How to do it…
How it works…
See also
Index
Ubuntu Server Cookbook
Ubuntu Server Cookbook
Copyright © 2016 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
First published: June 2016
Production reference: 1270616
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham B3 2PB, UK.
ISBN 978-1-78588-306-4
www.packtpub.com
Credits
Author
Uday R. Sawant
Reviewer
Dominik Jakub Szynk
Commissioning Editor
Neil Alexander
Acquisition Editor
Divya Poojari
Content Development Editor
Deepti Thore
Technical Editor
Devesh Chugh
Copy Editor
Safis Editing
Project Coordinator
Shweta H Birwatkar
Proofreader
Safis Editing
Indexer
Monica Ajmera Mehta
Graphics
Kirk D'Penha
Production Coordinator
Shantanu N. Zagade
Cover Work
Shantanu N. Zagade
About the Author
Uday R. Sawant has completed his master's in computer applications from Mumbai University. He is skilled with more than four years of experience in software development and operations field.
He is an expert with the LAMP stack, JavaScript, and cloud infrastructure. Before starting as a software developer, he worked extensively with server hardware and has more than two years of experience as system administrator.
Currently, he is working as a software scientist in a Mumbai-based start-up called Sweet Couch. His responsibilities include developing backend services, setting up real-time communication server, and automating various daily tasks. With immense interest in machine learning, he likes to spend his spare time exploring this subject. His first book was Instant Building Multi-Page Forms with Yii How-To published by Packt Publishing.
I would like to thank Packt Publishing for giving me another opportunity to work with them and write my second book. A big thanks goes to my parents for their support throughout the time of writing this book. Also, I would like to thank my team at Sweet Couch as without their support, it would have not been possible to write a full length book. A special thanks to Mr. Mitul Thakkar who always encouraged me to keep on writing. Finally, thanks to Preeti Singh, an editor for this book, for keeping things on track.
www.PacktPub.com
eBooks, discount offers, and more
Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.
https://www2.packtpub.com/books/subscription/packtlib
Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.
Why Subscribe?
Fully searchable across every book published by Packt
Copy and paste, print, and bookmark content
On demand and accessible via a web browser
Preface
Welcome to Ubuntu Server Cookbook, a step-by-step guide to your own Ubuntu server.
Ubuntu is an open source operating system, or rather, I should say that Ubuntu is a mission to provide quality software to everybody without any cost. As mentioned on the official site, the meaning of the word Ubuntu is I am, cause we are and Ubuntu is working hard towards their mission by being more than just a free operating system.
Ubuntu is based on Debian, a well-established Linux distribution. However, Debian is kind of limited to geeks. Ubuntu added an easy user interface named Unity that made it popular with various desktop users. One answer on Ask Ubuntu compares Ubuntu and Debian to a local restaurant and a farmer, respectively. Ubuntu carefully selects the best things from Debian and adds its own flavors to make it easy and more enjoyable for the end users. It's still Debian at base, but it more easier to use and more stable with frequent updates and a definite release cycle.
Users can choose an Ubuntu operating system from nine different flavors, starting with lightweight desktop to a fully loaded multimedia editing system. In addition to desktop systems, Ubuntu provides separate editions for various server platforms, cloud systems, mobile devices, and tablets. The new versions are released every six months with a major release in April and updates in October. All security updates are released throughout the year, as and when necessary. Every new version released in an even year (2014, 2016, and so on) are tagged for Long Term Support (LTS). These versions receive extended support period of five years and are generally used in production environments.
At the time of writing, Ubuntu has already taken a major share in the server market and has already become a default choice of millions of cloud users. According to an article by Dustin Kirkland, a member of the product team at Canonical, November 2015 has seen over 2 million cloud instances being launched with Ubuntu Server. That's nearly one instance per second
and these are just the numbers from cloud services. Ubuntu is being used in Desktop systems, laptops, mobiles, routers, and even to control your cars, drones, and countless Internet of Things (IoT) devices. Docker hub, a popular container repository reports more than 40 million pulls of official Ubuntu image.
The purpose of this book is to provide step-by-step solutions using the Ubuntu server. We will focus on common, server-related tasks such as user management, installing various packages for web servers, database, some low hanging fruits in performance and security, and many more. The book also covers the latest development in the container world with LXD and Docker. All recipes are based on the Ubuntu server, Xenial Xerus (version 16.04), the latest LTS release of Ubuntu.
What this book covers
The book is divided into multiple chapters, covering details of specific tasks.
Chapter 1, Managing Users and Groups, covers common user management tasks such as adding or removing user accounts, creating separate groups, assigning access rights, and setting user-level resource limits.
Chapter 2, Networking, explore the various network management functions, including network configuration, setting up DNS and DHCP servers, installing network proxy, and VPN setup. It also includes performance tuning tips and firewall setup.
Chapter 3, Working with Web Servers, provides a detailed configuration of web servers. This chapter covers both Apache and Nginx. You will also find some advance topics such as reverse proxy and load balancing using Nginx.
Chapter 4, Working with Mail Servers, explains the installation and configuration of your e-mail server.
Chapter 5, Handling Databases, discusses the popular relational database server, MySQL. It also covers MongoDB as a NoSQL database system, which is quite a hot technology in recent days.
Chapter 6, Network Storage, explains how to set up the good old Samba server along with FTP and Rsync details. Additionally, it includes the basics of NFS.
Chapter 7, Cloud Computing, includes details on virtualization with the Ubuntu server and some advance tools from Ubuntu to set up your own cloud system with OpenStack and Juju.
Chapter 8, Working with Containers, introduces Linux containers (LXC) and a container management tool by Ubuntu, LXD. This chapter also covers another hot topic, Docker.
Chapter 9, Streaming with Ampache, helps you to set up your own streaming server. We will take a quick look at Ampache, an open source web application for media streaming.
Chapter 10, Communication Server with XMPP, covers the installation of XMPP-based chat server, Ejabberd.
Chapter 11, Git Hosting, covers basic work flow of version control system Git and an open source web-based repository management tool GitLab.
Chapter 12, Collaboration Tools, explores more open source tools for your team and also covers the various tools to help your team stay connected.
Chapter 13, Performance Monitoring, introduces various monitoring tools that can help you optimize the performance of your Ubuntu server.
Chapter 14, Centralized Authentication Service, saves some efforts by introducing LDAP. This chapter covers the LDAP-based centralized authentication and authorization.
What you need for this book
The book is written with the help of Ubuntu server 16.04 and few virtual machines with VirtualBox. The recipes should work fine with Ubuntu version 14.04 and higher. For most of the recipes, a minimum hardware configuration of 512 MB memory with single CPU is enough. However, a few recipes such as OpenStack installation require additional hardware resources. The specific requirements are given in the respective recipes, if any.
Feel free to use any virtualization tool of your choice. Also, you can skip the local set up and use cloud servers. Many cloud providers give free introductory service for limited period. You can use these services to test your setup.
Who this book is for
Ubuntu Server Cookbook is intended for system administrators with a basic understanding of Linux operating system. If you are a software developer or a newbie system administrator and want to setup your own servers, this book is an ideal guide for you. You are not required to have an in-depth knowledge or hands-on experience with Ubuntu, but you should know the basic commands for directory navigation, file management, and file editing tool. An understanding of computer networks and Internet is advisable.
Sections
In this book, you will find several headings that appear frequently (Getting ready, How to do it…, How it works…, There's more…, and See also).
To give clear instructions on how to complete a recipe, we use these sections as follows:
Getting ready
This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.
How to do it…
This section contains the steps required to follow the recipe.
How it works…
This section usually consists of a detailed explanation of what happened in the previous section.
There's more…
This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.
See also
This section provides helpful links to other useful information for the recipe.
Conventions
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: You can check other log files like /var/log/mail.err and /var/log/upstart/dovecot.log
A block of code is set as follows:
disable_plaintext_auth = yes
Any command-line input or output is written as follows:
$ sudo adduser bob
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: You can access the Inbox panel on port 7071.
Note
Warnings or important notes appear in a box like this.
Tip
Tips and tricks appear like this.
Reader feedback
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <feedback@packtpub.com>, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Customer support
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
Downloading the example code
You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
You can download the code files by following these steps:
Log in or register to our website using your e-mail address and password.
Hover the mouse pointer on the SUPPORT tab at the top.
Click on Code Downloads & Errata.
Enter the name of the book in the Search box.
Select the book for which you're looking to download the code files.
Choose from the drop-down menu where you purchased this book from.
Click on Code Download.
You can also download the code files by clicking on the Code Files button on the book's webpage at the Packt Publishing website. This page can be accessed by entering the book's name in the Search box. Please note that you need to be logged in to your Packt account.
Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:
WinRAR / 7-Zip for Windows
Zipeg / iZip / UnRarX for Mac
7-Zip / PeaZip for Linux
The code bundle for the book is also hosted on GitHub at https://github.com/PacktPublishing/Ubuntu-Server-Cookbook. We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Downloading the color images of this book
We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: http://www.packtpub.com/sites/default/files/downloads/UbuntuServerCookbook_ColorImages.pdf.
Errata
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <copyright@packtpub.com> with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
Questions
If you have a problem with any aspect of this book, you can contact us at <questions@packtpub.com>, and we will do our best to address the problem.
Chapter 1. Managing Users and Groups
In this chapter, we will cover the following recipes:
Creating a user account
Creating user accounts in batch mode
Creating a group
Adding group members
Deleting a user account
Managing file permissions
Getting root privileges with sudo
Setting resource limits with limits.conf
Setting up public key authentication
Securing user accounts
Introduction
In this chapter, you will see how to add new users to the Ubuntu server, update existing users, and set permissions for users. You will get to know the default setting for new users and how to change them. Also, you will take a look at secure shell (SSH) access and securing user profiles.
Creating a user account
While installing Ubuntu, we add a primary user account on the server; if you are using the cloud image, it comes preinstalled with the default user. This single user is enough to get all tasks done in Ubuntu. There are times when you need to create more restrictive user accounts. This recipe shows how to add a new user to the Ubuntu server.
Getting ready
You will need super user or root privileges to add a new user to the Ubuntu server.
How to do it…
Follow these steps to create the new user account:
To add a new user in Ubuntu, enter following command in your shell:
$ sudo adduser bob
Enter your password to complete the command with sudo privileges:
Now enter a password for the new user:
Confirm the password for the new user:
Enter the full name and other information about the new user; you can skip this part by pressing the Enter key.
Enter Y to confirm that information is correct:
This should have added new user to the system. You can confirm this by viewing the file /etc/passwd:
How it works…
In Linux systems, the adduser command is higher level command to quickly add a new user to the system. Since adduser requires root privileges, we need to use sudo along with the command, adduser completes following operations:
Adds a new user.
Adds a new default group with the same name as the user.
Chooses UID (user ID) and GID (group ID) conforming to the Debian policy.
Creates a home directory with skeletal configuration (template) from /etc/skel.
Creates a password for the new user.
Runs the user script, if any.
If you want to skip the password prompt and finger information while adding the new user, use the following command:
$ sudo adduser --disabled-password --gecos username
Alternatively, you can use the useradd command as follows:
$ sudo useradd -s
Where:
-s specifies