Scripting user creation
User creation will now consist of three steps:
useradd
: This creates the userpasswd
: This sets the passwordsetquota
: 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 useuseradd -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 theusers
group.echo Password123 | passwd...