#!/bin/bash
echo "Enter new username"
read username
echo "Enter password for new user"
read password
echo "Enter string for authorized_keys from user id_rsa.pub"
read authorized_keys_string
sudo useradd -G admins -p password -s /bin/bash $username
sudo echo $username:$password | sudo chpasswd
sudo mkdir /home/$username
sudo mkdir /home/$username/.ssh
sudo chmod -R 777 /home/$username
sudo touch /home/$username/.ssh/authorized_keys
sudo chown -R $username:$username /home/$username
echo "$authorized_keys_string" | sudo tee -a /home/$username/.ssh/authorized_keys
sudo chmod -R 700 /home/$username
sudo chmod 600 /home/$username/.ssh/authorized_keys
sudo chown -R $username:$username /home/$username/.ssh/
sudo chage --mindays 0 --maxdays 365 --warndays 7 $username
sudo chage -l $username

