Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # 1) copy this file to target server (you may just use `nano` editor)
- # 2) run as ` script-name username password` (starting with space symbol to prevent writing password to bash commands history)
- ROOT_UID=0
- SUCCESS=0
- E_USEREXISTS=70
- E_NOTROOT=67
- # Run as root, of course. (this might not be necessary, because we have to run the script somehow with root anyway)
- if [ "$UID" -ne "$ROOT_UID" ]
- then
- echo "Must be root to run this script."
- exit $E_NOTROOT
- fi
- #test, if both argument are there
- if [ $# -eq 2 ]; then
- username=$1
- pass=$2
- # Check if user already exists.
- grep -q "$username" /etc/passwd
- if [ $? -eq $SUCCESS ]
- then
- echo "User $username does already exist."
- echo "please chose another username."
- exit $E_USEREXISTS
- fi
- apt install whois
- # useradd -p `mkpasswd "$pass"` -d /home/"$username" -m -g users -s /bin/bash "$username"
- useradd -p `mkpasswd "$pass"` -d "/home/$username" -m -s /bin/bash "$username"
- echo "$username ALL=(ALL:ALL) ALL" >> /etc/sudoers
- echo "the account was setup"
- else
- echo " this script needs 2 arguments you have given $# "
- echo " you have to call the script $0 username and the pass "
- fi
- exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement