correct perms on .ssh
[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     cp -r $HOME/.ssh/authorized_keys /home/me/.ssh/
29     chmod 0600 me:me /home/me/.ssh/authorized_keys
30     chown -R me:me /home/me/.ssh/
31
32     # Install webi for the new user
33     sudo -i -u me bash -c 'curl -fsSL https://webinstall.dev/webi | bash' \
34         || sudo -i -u me bash -c 'wget -q -O - https://webinstall.dev/webi | bash'
35
36     # TODO ensure that ssh-password login is off
37
38     echo "Created user 'me' with password '$my_password'"
39 }