3 homepage: https://webinstall.dev/ssh-adduser
5 SSH adduser: Because friends don't let friends login or run stuff as root
8 Many modern web programs (`npm` and `postgres`, for example) will not function correctly if run as root.
13 2. set a random, 32-character password (as a failsafe)
14 3. copy the `root` user's **`~/.ssh/authorized_keys`** (so the same users can still login)
15 4. give the `app` user `sudo` (admin) privileges
16 5. allow `app` to `sudo` without a password
19 How to create a new user named 'app':
22 # --disable-password prevents a password prompt
23 # --gecos "" skips the useless questions
24 adduser --disabled-password --gecos "" app
27 How to create a and set a random password:
30 # sets 'my_password' to 32 random hex characters (16 bytes)
31 my_password=$(openssl rand -hex 16)
33 # uses 'my_password' for to reset and confirm 'app's password
34 printf "$my_password"'\n'"$my_password" | passwd app
37 How to make the user 'app' a "sudo"er (an admin):
43 How to allow 'app' to run sudo commands without a password:
46 echo "app ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/app
49 How to copy allowed keys from root to the new user:
52 mkdir -p /home/app/.ssh/
53 chmod 0700 /home/app/.ssh/
55 cat "$HOME/.ssh/authorized_keys" >> /home/app/.ssh/authorized_keys
56 chmod 0600 /home/app/.ssh/authorized_keys
58 chown -R app:app /home/app/.ssh/