Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Mastering Ubuntu Server
Mastering Ubuntu Server

Mastering Ubuntu Server: Upgrade your Ubuntu skills

eBook
€8.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Mastering Ubuntu Server

Chapter 2. Managing Users

As an administrator of an Ubuntu Server, users can be your greatest asset and also your biggest headache. During your career you'll add countless new users, manage their passwords, remove their accounts when they leave the company, and grant or remove access to resources across the file-system. Even on servers on which you're the only user, you'll still find yourself managing user accounts since even system processes run as users. To be successful at managing Linux servers, you'll also need to know how to manage permissions, create password policies, and limit who can execute administrative commands on the machine. In this chapter, we'll work through these concepts so that you'll have a clear idea of how to manage users and their resources. In particular, we will cover:

  • Understanding when to use root
  • Creating and removing users
  • Understanding the /etc/passwd and /etc/shadow files
  • Distributing default configuration files with ...

Understanding when to use root

In the last chapter, we set up our very own Ubuntu Server installation. During the installation process, we were instructed to create a user account as an administrator of the system. So, at this point, we should have two users on our server. We have the aforementioned administrative user, as well as root. We can certainly create additional user accounts with varying levels of access (and we will do so in this chapter), but before we get to that, some discussion is in order regarding the administrator account you created, as well as the root user that was created for you.

In regards to root, the root user account exists on all Linux distributions and is the most powerful user account on the planet. The root user account can be used to do anything, and I do mean anything. Want to use root to create files and directories virtually anywhere on the file-system? No problem. Want to use root to install software? Again, not a problem. The root account can even be...

Creating and removing users

Creating users in Ubuntu can be done with one of either of two commands: adduser and useradd. This can be a little confusing at first, because both of these commands do the same thing (in different ways) and are named very similarly. I'll go over the useradd command first and then I'll explain how adduser differs. You may even prefer the latter, but we'll get to that in a moment.

First, here's an example of the useradd command in action:

# useradd -d /home/jdoe -m jdoe

Note

As I mentioned in the front matter for this book, whenever I prefix commands with a pound symbol (#), I'm instructing you to execute the command as root. You can use the actual root account for these types of commands or you can simply prefix the command with sudo. In the latter case, the command would become:

# sudo useradd -d /home/jdoe -m jdoe

I won't remind you of this henceforth, so just keep in mind commands prefixed with # need to be executed as root or with...

Understanding the /etc/passwd and /etc/shadow files

Now that we know how to create (and delete) user accounts on our server, we are well on our way to being able to manage our users. But where exactly is this information stored? We know that users store their personal files in /home, but is there some kind of database somewhere that keeps track of which user accounts are on our system? Actually, user account information is stored in two special text files: /etc/passwd and /etc/shadow.

You can display the contents of each of those two files with the following commands. Take note that any user can look at the contents of /etc/passwd, while only root has access to /etc/shadow:

# cat /etc/passwd
# cat /etc/shadow

Go ahead and take a look at these two files (just don't make any changes), and I will help you understand them. First, let's go over the /etc/passwd file. What follows is example output from this file on my test server. For brevity, I limited the output to the last seven lines...

Distributing default configuration files with /etc/skel

In a typical organization, there are usually some defaults that are recommended for users in terms of files and configuration. For example, in a company that performs software development, there are likely recommended settings for text editors and version control systems. Files that are contained within /etc/skel are copied into the home directory for all new users when you create them (assuming you've chosen to create a home directory while setting up the user).

In fact, you can see this for yourself right now. If you execute the following command, you can view the contents of the /etc/skel directory:

ls -la /etc/skel

You probably already know how to list files within a directory, but I specifically called out the -a parameter because the files included in /etc/skel by default are hidden (their file names begin with a period). I threw the -l parameter solely because I like it better (it shows a long list, which I think is easier...

Switching between users

Now that we have several users on our system, we need to know how to switch between them. Of course, you can always just log in to the server as one of the users, but you can actually switch to any user account at any time providing you either know that user's password or have root access.

The command you will use to switch from one user to another is the su command. If you enter su with no options, it will assume that you want to switch to root and will ask you for your root password. As I mentioned earlier, Ubuntu locks out the root account by default, so you really don't have a root password. Unlocking the root account is actually really simple; all you have to do is create a root password. To do that, you can execute the following command as any user with sudo access:

sudo passwd

The command will ask you to create and confirm your root password. From this point on, you will be able to use the root account as any other account. You can log in as root,...

Understanding when to use root


In the last chapter, we set up our very own Ubuntu Server installation. During the installation process, we were instructed to create a user account as an administrator of the system. So, at this point, we should have two users on our server. We have the aforementioned administrative user, as well as root. We can certainly create additional user accounts with varying levels of access (and we will do so in this chapter), but before we get to that, some discussion is in order regarding the administrator account you created, as well as the root user that was created for you.

In regards to root, the root user account exists on all Linux distributions and is the most powerful user account on the planet. The root user account can be used to do anything, and I do mean anything. Want to use root to create files and directories virtually anywhere on the file-system? No problem. Want to use root to install software? Again, not a problem. The root account can even be used...

Creating and removing users


Creating users in Ubuntu can be done with one of either of two commands: adduser and useradd. This can be a little confusing at first, because both of these commands do the same thing (in different ways) and are named very similarly. I'll go over the useradd command first and then I'll explain how adduser differs. You may even prefer the latter, but we'll get to that in a moment.

First, here's an example of the useradd command in action:

# useradd -d /home/jdoe -m jdoe

Note

As I mentioned in the front matter for this book, whenever I prefix commands with a pound symbol (#), I'm instructing you to execute the command as root. You can use the actual root account for these types of commands or you can simply prefix the command with sudo. In the latter case, the command would become:

# sudo useradd -d /home/jdoe -m jdoe

I won't remind you of this henceforth, so just keep in mind commands prefixed with # need to be executed as root or with the prefix sudo.

In this example...

Understanding the /etc/passwd and /etc/shadow files


Now that we know how to create (and delete) user accounts on our server, we are well on our way to being able to manage our users. But where exactly is this information stored? We know that users store their personal files in /home, but is there some kind of database somewhere that keeps track of which user accounts are on our system? Actually, user account information is stored in two special text files: /etc/passwd and /etc/shadow.

You can display the contents of each of those two files with the following commands. Take note that any user can look at the contents of /etc/passwd, while only root has access to /etc/shadow:

# cat /etc/passwd
# cat /etc/shadow

Go ahead and take a look at these two files (just don't make any changes), and I will help you understand them. First, let's go over the /etc/passwd file. What follows is example output from this file on my test server. For brevity, I limited the output to the last seven lines:

testuser...

Distributing default configuration files with /etc/skel


In a typical organization, there are usually some defaults that are recommended for users in terms of files and configuration. For example, in a company that performs software development, there are likely recommended settings for text editors and version control systems. Files that are contained within /etc/skel are copied into the home directory for all new users when you create them (assuming you've chosen to create a home directory while setting up the user).

In fact, you can see this for yourself right now. If you execute the following command, you can view the contents of the /etc/skel directory:

ls -la /etc/skel

You probably already know how to list files within a directory, but I specifically called out the -a parameter because the files included in /etc/skel by default are hidden (their file names begin with a period). I threw the -l parameter solely because I like it better (it shows a long list, which I think is easier to read...

Switching between users


Now that we have several users on our system, we need to know how to switch between them. Of course, you can always just log in to the server as one of the users, but you can actually switch to any user account at any time providing you either know that user's password or have root access.

The command you will use to switch from one user to another is the su command. If you enter su with no options, it will assume that you want to switch to root and will ask you for your root password. As I mentioned earlier, Ubuntu locks out the root account by default, so you really don't have a root password. Unlocking the root account is actually really simple; all you have to do is create a root password. To do that, you can execute the following command as any user with sudo access:

sudo passwd

The command will ask you to create and confirm your root password. From this point on, you will be able to use the root account as any other account. You can log in as root, switch to root...

Left arrow icon Right arrow icon

Key benefits

  • Get well-versed with newly-added features in Ubuntu 16.04
  • Master the art of installing, managing, and troubleshooting Ubuntu Server
  • A practical easy-to-understand book that will help you enhance your existing skills.

Description

Ubuntu is a Debian-based Linux operating system, and has various versions targeted at servers, desktops, phones, tablets and televisions. The Ubuntu Server Edition, also called Ubuntu Server, offers support for several common configurations, and also simplifies common Linux server deployment processes. With this book as their guide, readers will be able to configure and deploy Ubuntu Servers using Ubuntu Server 16.04, with all the skills necessary to manage real servers. The book begins with the concept of user management, group management, as well as file-system permissions. To manage your storage on Ubuntu Server systems, you will learn how to add and format storage and view disk usage. Later, you will also learn how to configure network interfaces, manage IP addresses, deploy Network Manager in order to connect to networks, and manage network interfaces. Furthermore, you will understand how to start and stop services so that you can manage running processes on Linux servers. The book will then demonstrate how to access and share files to or from Ubuntu Servers. You will learn how to create and manage databases using MariaDB and share web content with Apache. To virtualize hosts and applications, you will be shown how to set up KVM/Qemu and Docker and manage virtual machines with virt-manager. Lastly, you will explore best practices and troubleshooting techniques when working with Ubuntu Servers. By the end of the book, you will be an expert Ubuntu Server user well-versed in its advanced concepts.

Who is this book for?

This book is intended for readers with intermediate or advanced-beginner skills with Linux, who would like to learn all about setting up servers with Ubuntu Server. This book assumes that the reader knows the basics of Linux, such as editing configuration files and running basic commands.

What you will learn

  • Learn how to manage users, groups, and permissions
  • Encrypt and decrypt disks with Linux Unified Key Setup /Luks
  • Setup SSH for remote access, and connect it to other nodes
  • Understand how to add, remove, and search for packages
  • Use NFS and Samba to share directories with other users
  • Get to know techniques for managing Apache and MariaDB
  • Explore best practices and troubleshooting techniques

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 27, 2016
Length: 430 pages
Edition : 1st
Language : English
ISBN-13 : 9781785284526
Vendor :
Canonical
Concepts :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jul 27, 2016
Length: 430 pages
Edition : 1st
Language : English
ISBN-13 : 9781785284526
Vendor :
Canonical
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 120.97
Ubuntu Server Cookbook
€41.99
Mastering Ubuntu Server
€41.99
Practical Linux Security Cookbook
€36.99
Total 120.97 Stars icon
Banner background image

Table of Contents

15 Chapters
1. Deploying Ubuntu Server Chevron down icon Chevron up icon
2. Managing Users Chevron down icon Chevron up icon
3. Managing Storage Volumes Chevron down icon Chevron up icon
4. Connecting to Networks Chevron down icon Chevron up icon
5. Managing Software Packages Chevron down icon Chevron up icon
6. Controlling and Monitoring Processes Chevron down icon Chevron up icon
7. Managing Your Ubuntu Server Network Chevron down icon Chevron up icon
8. Accessing and Sharing Files Chevron down icon Chevron up icon
9. Managing Databases Chevron down icon Chevron up icon
10. Serving Web Content Chevron down icon Chevron up icon
11. Virtualizing Hosts and Applications Chevron down icon Chevron up icon
12. Securing Your Server Chevron down icon Chevron up icon
13. Troubleshooting Ubuntu Servers Chevron down icon Chevron up icon
14. Preventing and Recovering from Disasters Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.5
(10 Ratings)
5 star 70%
4 star 10%
3 star 20%
2 star 0%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




Kinger Nov 29, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Really an excellent tutorial on setting up and managing Ubuntu servers. I've subscribed to many online courses (assorted Udemy, Linux Academy subscription, Linux Foundation...) and this book has gotten me working and understanding much more quickly than the rest. Examples are very clear and the writing style is engaging, not the typical dry delivery of a lot of books on this topic. Highly recommended!
Amazon Verified review Amazon
Amazon Customer Jul 16, 2018
Full star icon Full star icon Full star icon Full star icon Full star icon 5
One of the best Linux server books I have read. Very thorough and detailed.This book is never on the shelf in the ops room and is always on someone's desk with the pages opened or has taken it home or is sitting in the server room next to a keyboard.Covers new OS issues.I have also seen some of Jay's work on Kubernetes, Sonatype, security, and AWS and found it a guide to survival in DevOps/DevSecOps world. I hope Jay will publish something in these areas as well in the future. Even a short guide or how to.
Amazon Verified review Amazon
klikmaker Oct 09, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I've never bought or read any of Jay LaCroix's books before, but based on the strength of his video tutorials I thought this would be a good buy. I mean, if a complete noob and dope like me can install Arch Linux from a guy's tutorials, a book by the same person should be good, right?The answer is: yup, right, definitely. I'm about 20% through the book and am certain I made a good choice. I have found everything to be clear, understandable, relevant, relatable, and jam-packed with good old common sense.It's an interesting experience in that his writing style is very much like his speaking style. I can practically hear his tutorial voice in my head as I read, and, as I intimated, that voice has been instrumental in me learning many Linux-esque things I otherwise would not have. (I wonder if he somehow "speaks" his books, then transcribes them?)So five stars from me. Thanks for writing this book, Jay.
Amazon Verified review Amazon
CCS4George Oct 20, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have been in the computer industry for over 20 years and I have always been a windows person. However, over the last 5-6 years I’ve started using Linux/Ubuntu as well. I purchased this book specifically to use as a handbook and as a reference for the many areas that I’m lacking. This book fills in knowledge gaps as well as help with best practices. There is a lot more I want to explore with Ubuntu and this book will help me with that.I highly recommend this book for anyone that is just starting out, just wants to understand the basics, or for the more advanced administrators that need to keep your skills well-polished.
Amazon Verified review Amazon
Mr. G. J. Sivill Dec 07, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Good text book on Ubuntu.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.