Book Image

CentOS System Administration Essentials

Book Image

CentOS System Administration Essentials

Overview of this book

Table of Contents (18 chapters)
CentOS System Administration Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
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...