From 500e51695fee962904c0ad678f3db4ab5cdcef6f Mon Sep 17 00:00:00 2001 From: sose Date: Wed, 19 Sep 2018 22:43:25 +0200 Subject: [PATCH] Addded ssh key auth --- README.md | 2 +- newuser.sh | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 74ffed9..30e82cf 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ contact ~ben or sose on tilde.chat (in the #slbr channel) to sign up. - Once all of your users are created and logged in, run `echo "1" > gamestatus` to start the game. ## TODO -- Handling of ssh keys and/or passwords - Install-time configuration (setting proper ips, hostname, etc.) +- A goal and a way to check it This is a ~ work in progress ~ diff --git a/newuser.sh b/newuser.sh index f2475e2..e0dbd02 100755 --- a/newuser.sh +++ b/newuser.sh @@ -5,15 +5,19 @@ 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 "$SLBRUSER:$SLBRUSER" "/home/slbr/$SLBRUSER" +sudo chown -R "$SLBRUSER:$SLBRUSER" "/home/slbr/$SLBRUSER" sudo chsh "$SLBRUSER" -s /home/slbr/login.sh -echo "Creating container..." +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" -mkdir "/home/slbr/$SLBRUSER/.ssh" -echo "$PUBKEY" >> "/home/slbr/$SLBRUSER/.ssh/authorized_keys"