Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
CentOS System Administration Essentials

You're reading from   CentOS System Administration Essentials Become an efficient CentOS administrator by acquiring real-world knowledge of system setup and configuration

Arrow left icon
Product type Paperback
Published in Nov 2014
Publisher Packt
ISBN-13 9781783985920
Length 174 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
Andrew Mallett Andrew Mallett
Author Profile Icon Andrew Mallett
Andrew Mallett
Arrow right icon
View More author details
Toc

Table of Contents (13) Chapters Close

Preface 1. Taming vi 2. Cold Starts FREE CHAPTER 3. CentOS Filesystems – A Deeper Look 4. YUM – Software Never Looked So Good 5. Herding Cats – Taking Control of Processes 6. Users – Do We Really Want Them? 7. LDAP – A Better Type of User 8. Nginx – Deploying a Performance-centric Web Server 9. Puppet – Now You Are the Puppet Master 10. Security Central 11. Graduation Day Index

Scripting user creation


User creation will now consist of three steps:

  • useradd: This creates the user

  • passwd: This sets the password

  • setquota: This sets the disk limits

We can ensure that all this happens correctly and uniformly using scripts to ensure the procedural integrity of the user creation process. It is also going to save you time. As a very quick solution, the following script provides all that we need:

#!/bin/bash
useradd -m -G users $1 
echo Password123 | passwd --stdin $1
passwd -e $1
setquota -u $1 20000 25000 0 0 /home

We will need to run the script with the new username as the argument, as shown in the following example:

# userscript.sh bob

Reading the script though line by line can explain the script contents as follows:

  • #!/bin/bash: This is the script interpreter to use

  • useradd -m -G users $1: This creates the user supplied as the first argument to the script, $1. The user's home directory will be created, and it will be added to the users group.

  • echo Password123 | passwd...

lock icon The rest of the chapter is locked
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 $19.99/month. Cancel anytime
Banner background image