X-Git-Url: https://git.josue.xyz/?a=blobdiff_plain;ds=sidebyside;f=ssh-utils%2Fssh-adduser.sh;h=e3ee4ff4edf73b55f2794ea7b0097219d070a5bd;hb=912c9c8f06590f06a2a9df1c03d8ead43e96ec70;hp=e6c71126f612a60d17994a3783c17dd29c6caf40;hpb=ace876458ef3f28922da6803a22278e0c7ed17ad;p=webi-installers%2F.git diff --git a/ssh-utils/ssh-adduser.sh b/ssh-utils/ssh-adduser.sh index e6c7112..e3ee4ff 100644 --- a/ssh-utils/ssh-adduser.sh +++ b/ssh-utils/ssh-adduser.sh @@ -15,32 +15,36 @@ #apt-get -y update #apt-get -y install curl wget rsync git - # Add User - # TODO: might there be a better name? - # me, this, user, self, person, i, who, do, tron - adduser --disabled-password --gecos "" me + # Add User app + # Picking 'app' because that seems to be what the # Docker/Vagrant + # crowd is doing. TODO: Other ideas? me, user, tron + my_name="${1:-"app"}" + adduser --disabled-password --gecos '' "$my_name" my_password=$(openssl rand -hex 16) - printf "$my_password"'\n'"$my_password" | passwd me + printf "$my_password"'\n'"$my_password" | passwd "$my_name" - # make 'me' a sudo-er (admin) - adduser me sudo - echo "me ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/me + # make 'app' a sudo-er (admin) + adduser "$my_name" sudo + echo "$my_name ALL=(ALL:ALL) NOPASSWD: ALL" | tee "/etc/sudoers.d/$my_name" - # allow users who can already login as 'root' to login as 'me' - mkdir -p /home/me/.ssh/ - chmod 0700 /home/me/.ssh/ - cp -r "$HOME/.ssh/authorized_keys" /home/me/.ssh/ - chmod 0600 /home/me/.ssh/authorized_keys - chown -R me:me /home/me/.ssh/ + # allow users who can already login as 'root' to login as 'app' + mkdir -p "/home/$my_name/.ssh/" + chmod 0700 "/home/$my_name/.ssh/" + cp -r "$HOME/.ssh/authorized_keys" "/home/$my_name/.ssh/" + chmod 0600 "/home/$my_name/.ssh/authorized_keys" + touch "/home/$my_name/.ssh/config" + chmod 0644 "/home/$my_name/.ssh/config" + chown -R "$my_name":"$my_name" "/home/$my_name/.ssh/" - # ensure that 'me' has an SSH Keypair - sudo -i -u me bash -c 'ssh-keygen -b 2048 -t rsa -f /home/me/.ssh/id_rsa -q -N ""' + # ensure that 'app' has an SSH Keypair + sudo -i -u "$my_name" bash -c "ssh-keygen -b 2048 -t rsa -f '/home/$my_name/.ssh/id_rsa' -q -N ''" - # Install webi for the new 'me' user - sudo -i -u me bash -c 'curl -fsSL https://webinstall.dev/webi | bash' \ - || sudo -i -u me bash -c 'wget -q -O - https://webinstall.dev/webi | bash' + # Install webi for the new 'app' user + WEBI_HOST=${WEBI_HOST:-"https://webinstall.dev"} + sudo -i -u "$my_name" bash -c "curl -fsSL '$WEBI_HOST/webi' | bash" \ + || sudo -i -u "$my_name" bash -c "wget -q -O - '$WEBI_HOST/webi' | bash" # TODO ensure that ssh-password login is off - echo "Created user 'me' with password '$my_password'" + echo "Created user '$my_name' with password '$my_password'" }