mirror of
https://github.com/webinstall/webi-installers.git
synced 2026-08-23 22:16:48 +00:00
add some vps setup utils
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
---
|
||||
title: Adduser
|
||||
homepage: https://webinstall.dev/adduser
|
||||
tagline: |
|
||||
Because friends don't let friends run as root
|
||||
linux: true
|
||||
description: |
|
||||
Adds user `bob` with the same **`~/.ssh/authorized_keys`** as the root user, exiting early if run by a non-root user.
|
||||
---
|
||||
|
||||
Check that `bob` exists
|
||||
|
||||
```bash
|
||||
ls /home/
|
||||
```
|
||||
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
set -u
|
||||
|
||||
# TODO: a more complete VPS setup
|
||||
|
||||
# TODO would $EUID be better?
|
||||
if [ "root" != "$(whoami)" ]; then
|
||||
echo "webi adduser: running user is already a non-root user"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#apt-get -y update
|
||||
#apt-get -y install curl wget rsync git
|
||||
|
||||
# Add User
|
||||
adduser --disabled-password --gecos "" bob
|
||||
my_password=$(openssl rand -hex 16)
|
||||
printf "$my_password"'\n'"$my_password" | passwd bob
|
||||
adduser bob sudo
|
||||
echo "bob ALL=(ALL:ALL) NOPASSWD: ALL" | tee /etc/sudoers.d/bob
|
||||
sudo -i -u bob bash -c 'ssh-keygen -b 2048 -t rsa -f /home/bob/.ssh/id_rsa -q -N ""'
|
||||
mkdir -p /home/bob/.ssh/
|
||||
cp -r $HOME/.ssh/authorized_keys /home/bob/.ssh/
|
||||
chmod 0600 bob:bob /home/bob/.ssh/authorized_keys
|
||||
chown -R bob:bob /home/bob/.ssh/
|
||||
|
||||
# Install webi for the new user
|
||||
sudo -i -u bob bash -c 'curl -fsSL https://webinstall.dev/webi | bash' \
|
||||
|| sudo -i -u bob bash -c 'wget -q -O - https://webinstall.dev/webi | bash'
|
||||
|
||||
# TODO ensure that ssh-password login is off
|
||||
|
||||
echo "Created user 'bob' with password '$my_password'"
|
||||
Reference in New Issue
Block a user