deployment/scripts/serviceaccount.sh

28 lines
930 B
Bash
Raw Normal View History

#!/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)"
useradd -m -s /bin/bash ${USERNAMETOADD}
2024-12-06 20:53:57 -05:00
echo "user added"
echo "${USERNAMETOADD}:${PASSWORDTOADD}" | chpasswd
2024-12-06 20:53:57 -05:00
echo "password updated"
loginctl enable-linger ${USERNAMETOADD}
2024-12-06 20:53:57 -05:00
echo "linger enabled"
mkdir /home/${USERNAMETOADD}/.ssh
2024-12-06 20:53:57 -05:00
echo "user has .ssh/"
touch /home/${USERNAMETOADD}/authorized_keys
2024-12-06 20:53:57 -05:00
echo "user has .ssh/authorized keys"
cat ssh.pub >> /home/${USERNAMETOADD}/.ssh/authorized_keys
2024-12-06 20:53:57 -05:00
echo "authorized keys should accept ssh.pub"
chmod 600 /home/${USERNAMETOADD}/authorized_keys
2024-12-06 20:53:57 -05:00
echo "authorized keys should be mode 600"
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 18:04:58 -05:00
echo "${SUDOER_PSW}" | sudo -S bash -c "$(declare -f restofscript); restofscript"
exit