update ssh-adduser
[webi-installers/.git] / ssh-utils / ssh-adduser.sh
1 #!/bin/bash
2
3 {
4     set -e
5     set -u
6
7     # TODO: a more complete VPS setup
8
9     # TODO would $EUID be better?
10     if [ "root" != "$(whoami)" ]; then
11       echo "webi adduser: running user is already a non-root user"
12       exit 0
13     fi
14
15     #apt-get -y update
16     #apt-get -y install curl wget rsync git
17
18     # Add User
19     # TODO: might there be a better name?
20     # me, this, user, self, person, i, who, do, tron
21     adduser --disabled-password --gecos "" me
22     my_password=$(openssl rand -hex 16)
23     printf "$my_password"'\n'"$my_password" | passwd me
24     adduser me sudo
25     echo "me ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/me
26     sudo -i -u me bash -c 'ssh-keygen -b 2048 -t rsa -f /home/me/.ssh/id_rsa -q -N ""'
27     mkdir -p /home/me/.ssh/
28     chmod 0700 /home/me/.ssh/
29     cp -r "$HOME/.ssh/authorized_keys" /home/me/.ssh/
30     chmod 0600 /home/me/.ssh/authorized_keys
31     chown -R me:me /home/me/.ssh/
32
33     # Install webi for the new user
34     sudo -i -u me bash -c 'curl -fsSL https://webinstall.dev/webi | bash' \
35         || sudo -i -u me bash -c 'wget -q -O - https://webinstall.dev/webi | bash'
36
37     # TODO ensure that ssh-password login is off
38
39     echo "Created user 'me' with password '$my_password'"
40 }