mirror of
https://github.com/elAgala/server-initializer.git
synced 2026-02-13 21:06:16 +00:00
25 lines
750 B
Bash
25 lines
750 B
Bash
#!/bin/bash
|
|
|
|
function create_user() {
|
|
username=$1
|
|
|
|
home_dir="/home/$username"
|
|
|
|
echo "[ USER ]: Starting user $username setup"
|
|
sudo useradd -m -s /bin/bash $username
|
|
password="${ADMIN_PASSWORD:-$(openssl rand -base64 16)}"
|
|
echo "$username:$password" | sudo chpasswd
|
|
echo "[ USER ]: Password set for $username (use ADMIN_PASSWORD env var to specify)"
|
|
echo "[ USER ]: User created succesfully"
|
|
|
|
echo "[ USER ]: Adding user to groups"
|
|
sudo usermod -aG sudo $username
|
|
sudo usermod -aG www-data $username
|
|
echo "[ USER ]: User added to the following groups (sudo, www-data)"
|
|
|
|
echo "[ USER ]: Setting ownership of /home/$username folder"
|
|
sudo chown -R $username:$username /home/$username
|
|
|
|
echo "[ USER ]: User setup finished"
|
|
}
|