SpectreOS-old/addusers.sh

66 lines
1.3 KiB
Bash
Raw Permalink Normal View History

2018-02-26 02:41:29 +01:00
!/bin/bash
#
set -ex
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
sudo $0
exit 0
fi
echo "Als root Angemeldet"
#
2018-03-18 18:24:31 +01:00
function addusers() {
2018-02-26 02:41:29 +01:00
useradd -m -g users -G wheel,audio,video,sys,optical -s /bin/bash $username
passwd ${username} <<EOT
${userpass}
${userpass}
EOT
mkdir -p /home/"$username"/
userrechte
}
function copyconfig() {
cp -aRv /root/. /home/"$username"/
#links
userrechte
}
function userrechte() {
#user
chown -cR -v "$username":users /home/"$username"
chmod 750 -Rv /home/"$username"
#ssh
chmod 755 /home/"$username"/
if [ -d /home/"$username"/.ssh ]; then
chmod 700 /home/"$username"/.ssh
fi
if [ -f /home/"$username"/.ssh/id_rsa ]; then
chmod 600 /home/"$username"/.ssh/id_rsa
fi
if [ -f /home/"$username"/.ssh/authorized_keys ]; then
chmod 600 /home/"$username"/.ssh/authorized_keys
fi
#root
chmod 750 -Rv /root
#ssh-root
chmod 755 /root/
if [ -d /root/.ssh ]; then
chmod 700 /root/.ssh
fi
if [ -f /root/.ssh/id_rsa ]; then
chmod 600 /root/.ssh/id_rsa
fi
if [ -f /root/.ssh/authorized_key ]; then
chmod 600 /root/.ssh/authorized_keys
fi
}
username="$1"
userpass="$2"
2018-03-18 18:24:31 +01:00
addusers
2018-02-26 02:41:29 +01:00
copyconfig
echo "Fertig!!!"