SLBR/newuser.sh

24 lines
858 B
Bash
Executable File

#!/bin/sh
SLBRUSER=$1
PUBKEY=$2
test -z "$SLBRUSER" && echo "no user provided" && exit
echo "Creating homedir..."
mkdir "/home/slbr/$SLBRUSER"
mkdir "/home/slbr/$SLBRUSER/.ssh"
echo "Copying key..."
echo "$PUBKEY" >> "/home/slbr/$SLBRUSER/.ssh/authorized_keys"
echo "$SLBRUSER" >> users
echo "Creating container..."
echo "lxc exec $SLBRUSER bash" > "/home/slbr/$SLBRUSER/.profile"
chmod -w "/home/slbr/$SLBRUSER/.profile"
echo "Creating user..."
sudo useradd "$SLBRUSER" -d "/home/slbr/$SLBRUSER"
sudo usermod -a -G lxd "$SLBRUSER"
sudo chown -R "$SLBRUSER:$SLBRUSER" "/home/slbr/$SLBRUSER"
sudo chsh "$SLBRUSER" -s /home/slbr/login.sh
echo "Generating user keypair..."
sudo su "$SLBRUSER" -s /bin/sh -c "ssh-keygen -t rsa -N '' -f /home/slbr/$SLBRUSER/.ssh/id_rsa"
echo "Initializing container..."
sudo su "$SLBRUSER" -s /bin/sh -c "/home/slbr/lxcinit.sh"