Skip to content

Commit 083fea4

Browse files
authored
Merge pull request #4 from Web3-Pi/2fa
2fa for cockpit in advanced setup
2 parents 5612de1 + 06424d0 commit 083fea4

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

docs/advanced-setup/2fa.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Two-Factor Authentication (2FA) for Cockpit
2+
3+
Adding Two-Factor Authentication (2FA) to Cockpit increases the security of your server by requiring a time-based one-time password (TOTP) in addition to your regular credentials.
4+
5+
## Step 1: Install Required Packages
6+
7+
Open a terminal and run:
8+
9+
```sh
10+
sudo apt-get install libpam-google-authenticator -y
11+
```
12+
13+
This installs the PAM module for Google Authenticator.
14+
15+
## Step 2: Configure Google Authenticator for Your User
16+
17+
Run the following command to set up Google Authenticator with recommended options:
18+
19+
```sh
20+
google-authenticator -t -d -f -r 3 -R 30 -W -Q UTF8
21+
```
22+
23+
!!! note
24+
25+
- `-t` use TOTP instead of HOTP (recommended).
26+
- `-d` disable reuse of previously used TOTP tokens.
27+
- `-f` disable confirmation before writing the `~/.google_authenticator` file.
28+
- `-r 3 -R 30` limits the number of login attempts to 3 every 30 seconds.
29+
- `-W` by default google-authenticator allows the use of codes that were generated a little before or a little after the current time. This option disables that feature (recommended for security).
30+
- `-Q UTF8` specifies the encoding for the QR code. Change to `-Q ANSI` if you're having issues with viewing the QR code.
31+
32+
- This will generate a secret key, QR code, and emergency scratch codes.
33+
- Scan the QR code with your preferred authenticator app (e.g., Google Authenticator, Authy).
34+
- Enter the verification code from your authenticator app to complete the setup.
35+
- Save the emergency scratch codes in a safe place.
36+
37+
!!! note
38+
39+
Scratch codes are one-time use only. If you lose access to your authenticator app, enter one of these codes to log in and recreate your 2FA setup.
40+
41+
## Step 3: Enable 2FA for Cockpit
42+
43+
Use the following command to add the Google Authenticator PAM module to the Cockpit PAM configuration:
44+
45+
```sh
46+
sudo bash -c 'echo "auth required pam_google_authenticator.so nullok" >> /etc/pam.d/cockpit'
47+
```
48+
49+
This tells Cockpit to require a TOTP code during login.
50+
51+
!!! note
52+
53+
- The `nullok` option disables 2FA for users that do not have a `~/.google_authenticator` file.
54+
55+
## Step 4: Restart Cockpit
56+
57+
Restart the Cockpit service to apply the changes:
58+
59+
```sh
60+
sudo systemctl restart cockpit
61+
```
62+
63+
## Step 5: Test Your Setup
64+
65+
1. Log out of Cockpit.
66+
2. Log back in. You should be prompted for a verification code from your authenticator app.
67+
68+
![Verification Code Prompt](../img/cockpit-verification-code.png)
69+
70+
71+
## Uninstalling 2FA
72+
73+
To remove 2FA from Cockpit, simply delete the line you added to the PAM configuration:
74+
75+
```sh
76+
sudo bash -c 'sed -i "/pam_google_authenticator.so nullok/d" /etc/pam.d/cockpit'
77+
```
78+
79+
Then restart the Cockpit service:
80+
81+
```sh
82+
sudo systemctl restart cockpit
83+
```
84+
85+
You can also remove the generated `~/.google_authenticator` file and the installed packages if you no longer need 2FA:
86+
87+
```sh
88+
sudo apt remove libpam-google-authenticator -y
89+
rm ~/.google_authenticator
90+
```

docs/advanced-setup/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This section provides advanced setup guides for your Web3 Pi node that aim to op
44

55
## Table of Contents
66

7+
- [Two-Factor Authentication (2FA)](2fa.md) - Add an extra layer of security to your Cockpit login.
78
- [Backup Power](ups.md) - Consider adding a backup power source to your node, in case of power outages.
89
- [Power over Ethernet](poe.md) - Use PoE (Power over Ethernet) instead of the included power supply.
910
- [Firewall Configuration (UFW)](ufw.md) - Configure UFW to control incoming and outgoing network traffic.
51 KB
Loading

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ nav:
103103
- Next Steps: 'setup/next-steps.md'
104104
- Advanced Setup:
105105
- 'advanced-setup/index.md'
106+
- Two-Factor Authentication (2FA): 'advanced-setup/2fa.md'
106107
- Backup Power: 'advanced-setup/ups.md'
107108
- Power over Ethernet: 'advanced-setup/poe.md'
108109
- Firewall Configuration (UFW): 'advanced-setup/ufw.md'

0 commit comments

Comments
 (0)