2024-12-06 17:06:04 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
SUDOER_PSW=
|
|
|
|
|
|
|
|
function restofscript(){
|
2024-12-06 18:04:58 -05:00
|
|
|
USERNAMETOADD=
|
|
|
|
PASSWORDTOADD=
|
2024-12-06 20:53:57 -05:00
|
|
|
echo "hello, $(whoami)"
|
2024-12-06 17:06:04 -05:00
|
|
|
useradd -m -s /bin/bash ${USERNAMETOADD}
|
2024-12-06 20:53:57 -05:00
|
|
|
echo "user added"
|
2024-12-06 17:06:04 -05:00
|
|
|
echo "${USERNAMETOADD}:${PASSWORDTOADD}" | chpasswd
|
2024-12-06 20:53:57 -05:00
|
|
|
echo "password updated"
|
2024-12-06 17:06:04 -05:00
|
|
|
loginctl enable-linger ${USERNAMETOADD}
|
2024-12-06 20:53:57 -05:00
|
|
|
echo "linger enabled"
|
2024-12-06 20:39:16 -05:00
|
|
|
mkdir /home/${USERNAMETOADD}/.ssh
|
2024-12-06 20:53:57 -05:00
|
|
|
echo "user has .ssh/"
|
2024-12-06 20:39:16 -05:00
|
|
|
touch /home/${USERNAMETOADD}/authorized_keys
|
2024-12-06 20:53:57 -05:00
|
|
|
echo "user has .ssh/authorized keys"
|
2024-12-06 20:39:16 -05:00
|
|
|
cat ssh.pub >> /home/${USERNAMETOADD}/.ssh/authorized_keys
|
2024-12-06 20:53:57 -05:00
|
|
|
echo "authorized keys should accept ssh.pub"
|
2024-12-06 20:39:16 -05:00
|
|
|
chmod 600 /home/${USERNAMETOADD}/authorized_keys
|
2024-12-06 20:53:57 -05:00
|
|
|
echo "authorized keys should be mode 600"
|
2024-12-06 20:39:16 -05:00
|
|
|
chown -R "${USERNAMETOADD}:${USERNAMETOADD}" /home/${USERNAMETOADD}/.ssh
|
2024-12-06 20:53:57 -05:00
|
|
|
echo "correct user should own his .ssh directory. done!"
|
2024-12-06 17:06:04 -05:00
|
|
|
}
|
|
|
|
|
2024-12-06 18:04:58 -05:00
|
|
|
echo "${SUDOER_PSW}" | sudo -S bash -c "$(declare -f restofscript); restofscript"
|
|
|
|
exit
|