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 ...

Get CentOS System Administration Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.