update info about command
[webi-installers/.git] / ssh-adduser / README.md
1 ---
2 title: SSH adduser
3 homepage: https://webinstall.dev/ssh-adduser
4 tagline: |
5   SSH adduser: Because friends don't let friends login or run stuff as root
6 linux: true
7 description: |
8   Many modern web programs (`npm` and `postgres`, for example) will not function correctly if run as root.
9
10   `ssh-adduser` will
11
12     1. add the user `me`
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 `me` user `sudo` (admin) privileges
16     5. allow `me` to `sudo` without a password
17 ---
18
19 How to create a new user named 'me':
20
21 ```bash
22 # --disable-password prevents a password prompt
23 # --gecos "" skips the useless questions
24 adduser --disabled-password --gecos "" me
25 ```
26
27 How to create a and set a random password:
28
29 ```bash
30 # sets 'my_password' to 32 random hex characters (16 bytes)
31 my_password=$(openssl rand -hex 16)
32
33 # uses 'my_password' for to reset and confirm 'me's password
34 printf "$my_password"'\n'"$my_password" | passwd me
35 ```
36
37 How to make the user 'me' a "sudo"er (an admin):
38
39 ```bash
40 adduser me sudo
41 ```
42
43 How to allow 'me' to run sudo commands without a password:
44
45 ```bash
46 echo "me ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/me
47 ```
48
49 How to copy allowed keys from root to the new user:
50
51 ```bash
52 mkdir -p /home/me/.ssh/
53 chmod 0700 /home/me/.ssh/
54
55 cat "$HOME/.ssh/authorized_keys" >> /home/me/.ssh/authorized_keys
56 chmod 0600 /home/me/.ssh/authorized_keys
57
58 chown -R me:me /home/me/.ssh/
59 ```