| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #!/bin/bash
- # Licence : GPL v3
- # Author: Laurent HUBERT
- #
- # Creates a new user for administrative purposes (in sudo group)
- #
- cat <<EOF
- +---------------------------------------------+
- | Creating default user |
- +---------------------------------------------+
- EOF
- read -p "Please enter default user name: " the_user
- if [ -n "$the_user" ]
- then
- echo Creating user $the_user
- # Creates the user but disable the login to set the password later:
- adduser --gecos ,,,, --disabled-login $the_user
- status=$?
- else
- # Exit with non zero status
- exit 1
- fi
- if [ 0 -ne "$status" ]
- then
- echo "### Error creating $the_user ###"
- echo "### Please try again by rebooting your system ###"
- exit 1
- else
- # Adds new user to sudo group
- adduser $the_user sudo
- fi
- status=1
- while [ 0 -ne "$status" ]
- do
- passwd $the_user
- status=$?
- if [ 0 -ne "$status" ]
- then
- echo "# Error changing $the_user password #"
- echo "Please try again"
- else
- echo "> $the_user : created successfully <"
- exit 0
- fi
- done
- echo "### An error occurred changing $the_user password ###"
- exit $status
|