2023-12-28 15:09:21 +01:00
# Users
It might be nice to add a user to your system.
2024-08-10 21:54:34 +02:00
## Wheel
2024-07-08 12:56:43 +02:00
2024-07-10 22:26:12 +02:00
Before creating the user install `doas` , to use when root is required:
2023-12-28 15:09:21 +01:00
```
# apk add doas
```
2024-07-10 22:26:12 +02:00
Configure `doas` through `/etc/doas.d/main.conf` :
2023-12-28 15:09:21 +01:00
```
permit persist :wheel as root
2024-05-09 12:27:11 +02:00
permit nopasss :_power cmd /sbin/poweroff
permit nopasss :_power cmd /sbin/reboot
2023-12-28 15:18:15 +01:00
```
2024-07-10 22:26:12 +02:00
and create a `_power` group for users to be able to poweroff the system without root:
2023-12-28 15:18:15 +01:00
```
# addgroup -S _power
2023-12-28 15:09:21 +01:00
```
## Adding a user
2024-07-10 22:26:12 +02:00
Adding a user in Alpine Linux can be done using the `setup-user` script. Here we can specify the name, full name with `-f` , groups and more:
2023-12-28 15:09:21 +01:00
```
2024-07-08 12:56:43 +02:00
# setup-user -g wheel,_power -f "<Full Name>" <username>
2023-12-28 15:09:21 +01:00
# passwd <username>
```
2024-07-10 22:26:12 +02:00
> It is recommended to have an "admin" account which is the sole account in the wheel group.
2023-12-28 16:13:04 +01:00
2024-07-10 22:26:12 +02:00
You may have to change the shell of the user in `/etc/passwd` from `/sbin/nologin` to a shell from `/etc/shells` . Alpine Linux comes with `/bin/ash` by default:
2023-12-28 16:04:13 +01:00
```
< username > :x:1234:1234:< Full Name > :/home/< username > :/bin/< shell >
```
2024-07-10 22:26:12 +02:00
> Do not log in yet if you want to encrypt the user's home directory.
2023-12-28 15:09:21 +01:00
2024-07-10 22:26:12 +02:00
If you have checked that `doas` works with the user then you can lock the root account because it imposes security risks if it is kept open. This can be done with:
2023-12-28 15:09:21 +01:00
```
# passwd -l root
```
2024-07-10 22:26:12 +02:00
and editing `/etc/passwd` to change the login shell from `/bin/ash` to `/sbin/nologin` :
2023-12-28 15:09:21 +01:00
```
root:x:0:0:root:/root:/sbin/nologin
```
2024-07-10 22:26:12 +02:00
## Encrypting the home directory
2024-07-08 12:56:43 +02:00
2024-07-10 22:26:12 +02:00
> Not yet working, DO NOT FOLLOW.
2024-07-08 12:56:43 +02:00
2024-07-10 22:26:12 +02:00
If you are running a system with multiple users or if you want an extra layer of protection then it is possible to encrypt every user's home directory.
2023-12-28 15:09:21 +01:00
> Do note that a second layer of encryption can lead to lower disk performance so in the case where this is important it might be preferred not to encrypt.
2023-12-29 21:33:58 +01:00
First install the `fscrypt` and `e2fsprogs-extra` packages:
2023-12-28 15:09:21 +01:00
```
2023-12-29 21:33:58 +01:00
# apk add fscrypt e2fsprogs-extra
2023-12-28 15:09:21 +01:00
```
Then make sure our filesystem has the `encrypt` feature enabled and setup `fscrypt` on the home directory:
```
2024-01-06 16:55:36 +01:00
# tune2fs -O encrypt /dev/vg<n>/alp_home
2023-12-28 15:09:21 +01:00
# fscrypt setup
# fscrypt setup /home
```
2023-12-29 21:44:44 +01:00
And in `/etc/pam.d/login` add these lines to their corresponding sections:
2023-12-28 15:09:21 +01:00
```
auth optional pam_fscrypt.so
...
session optional pam_fscrypt.so
```
2024-07-10 22:26:12 +02:00
Then encrypt the home directory with:
2023-12-28 15:09:21 +01:00
```
# fscrypt encrypt /home/<username> --user=<username>
2023-12-28 16:04:13 +01:00
[Create a new login protector]
[Enter 1 so that it unlocks the directory when the user logs in]
2023-12-28 15:09:21 +01:00
```
2023-12-28 16:04:13 +01:00
Then reboot and login with the user to check if it worked. It should also have given you a recovery password which should be stored somewhere safely (like Bitwarden). To check the status of the directory run:
2023-12-28 15:09:21 +01:00
```
$ fscrypt status /home/< username >
```
2023-12-28 16:04:13 +01:00
## TLDR
If you have already set up a system with a user but want to add another do this:
```
2023-12-30 22:48:50 +01:00
# setup-user -g (wheel,)nix,_power -f "<Full Name>" <username>
2023-12-28 16:04:13 +01:00
# passwd <username>
[Change shell in /etc/passwd]
2023-12-28 16:31:21 +01:00
# fscrypt encrypt /home/<username> --user=<username> # Doesn't work yet
2023-12-28 16:04:13 +01:00
[Create a new login protector]
[Enter 1 so that it unlocks the directory when the user logs in]
```