I need to create a shell script that will create a user then put it into a group. How do I do it?
Your question is a bit vague because you haven't really said what you need this for.
I'm assuming you need arguments as well so first create the script, so in the terminal type nano scriptname.sh and past in the script below.
#!/bin/bash
#$1 username
#$2 home directory
useradd $1 -U -m -d $2
If you type 'man useradd' you will see that -U creates a group with the same name as the user, -m creates the home directory and -d specifics the path to the home directory.
To use this script type chmod +x scriptname.sh to make the script executable and then type ./scriptname.sh
So for example to create a user called bob with the users home being /home/bob type:
./scriptname.sh bob /home/bob
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments