2FAuth is a web app for your two-factor codes. Instead of storing them only in an authenticator app on your smartphone, you can store your 2FA accounts on your own server and access one-time codes from any browser, on your PC as well as your phone. 2FAuth generates time-based codes (TOTP), counter-based codes (HOTP), and Steam Guard codes. You can add accounts using a QR code, an image upload, or manually, or import them from Google Authenticator, Aegis, 2FAS, and other apps.
Because 2FAuth stores the keys to your two-factor logins, it is a particularly sensitive application. This guide therefore focuses on secure settings: closed registration, an encrypted database, and regular backups.
We’ll show you two ways to install it: the simple way, as a One-Click App, and a manual installation with Docker Compose. Then you’ll add your first accounts, import existing codes, and set up passkeys.
Running 2FAuth on your own VPS is the right choice if:
- You need your 2FA codes on multiple devices. Access them in a browser on your PC, laptop, and smartphone without setting up each device individually.
- You don’t want to be locked out if your smartphone is lost or broken. Your codes are stored on the server, not just in an app on your phone.
- You don’t want to store your secrets with a cloud provider. The database is on your VPS, and 2FAuth can also encrypt it.
- Several people need access to the same accounts. As an administrator, you can add other users and share accounts with them.
- You want to switch from another app. 2FAuth imports exports from Google Authenticator, Aegis, 2FAS, FreeOTP+, and Bitwarden.
2FAuth is less suitable if you need your codes when you’re completely offline. Without a connection to your server, you can’t access your codes. Always keep the recovery codes for important accounts from the respective services. If you’re looking for a password manager that also stores 2FA codes, Vaultwarden is a better fit.
The quickest way to get started with 2FAuth is through your VPS’s One-Click Apps. The One-Click App sets up the domain with HTTPS, creates your administrator account from the form on first launch, and then closes registration. This means nobody else can create an account on your instance, even in the first few seconds after launch. You don’t need the console.
- A Linux VPS (Debian or Ubuntu) with One-Click Apps set up. See Set Up One-Click Apps for instructions.
- At least 1 vCore, 256 MB of free RAM, and 2 GB of storage. 512 MB of RAM and 5 GB of storage are recommended. 2FAuth is very lightweight and runs well alongside other apps.
- A domain for the app. You can get started right away with a zap.cloud subdomain. A custom domain such as
2fa.example.commust first point to your VPS via DNS. Passkeys only work with HTTPS, which the One-Click App sets up automatically.
- Open your VPS in the ZapX Dashboard and go to the One-Click Apps tab.
- Search the App catalog for 2FAuth and click Install app.
- Leave Use a custom subdomain or zap.cloud selected and choose a subdomain or your own domain.
- Under App configuration, enter the email address and password for your administrator account. All fields are listed in the table below.
- Click Queue installation. After about one or two minutes, 2FAuth will show as online on the app card.
| Field | Required | Default value | Description |
|---|---|---|---|
ADMIN_EMAIL | yes | – | Email address for your administrator account; use it to log in |
ADMIN_PASSWORD | yes | – | Administrator account password, at least 8 characters |
ADMIN_NAME | no | admin | Administrator’s display name in the interface |
Someone with access to 2FAuth can generate the second factors for your accounts. Use a long, unique password from your password manager. 2FAuth only requires 8 characters, but you should use many more.
The email address does not need to be reachable; it is only used as a username. The form is only processed on the very first launch. If you later change ADMIN_PASSWORD in the app settings, your password in 2FAuth will stay the same. You can reset your password in 2FAuth itself; see below.
- Click Access link on the app card. The 2FAuth login page will open.
- Log in using the email address and password from the form. The labels in this guide are from the English interface, but 2FAuth will display in your browser’s language.
- After logging in, you’ll see the No 2FA here! page. This is where you add your first account. See “Add and Manage Accounts” below for details.
You can find your credentials later in the app settings (gear icon) under App environment. You’ll also see two Automatically generated values, SERVICE_PASSWORD_TWOFAUTH and SERVICE_PASSWORD_TWOFAUTHPAD. The One-Click App uses them to generate 2FAuth’s secret app key.
2FAuth uses the app key to encrypt sessions and, if you enable it, your 2FA secrets. If you change either value, all sessions become invalid and encrypted data can no longer be read. Also save both values in your password manager, as you’ll need them to restore a backup.
Three settings are worth changing right after your first login. You’ll find them in the menu next to your email address at the bottom of the page.
- Encrypt data: Under Admin panel > App setup, enable Protect sensitive data in the Security section. 2FAuth will then store 2FA secrets and email addresses encrypted in the database. Nobody can read them without the app key from the app environment.
- Add a passkey: Under Settings > WebAuthn, register a passkey or security key. Afterward, you can log in from the login page with a security device, without a password.
- Keep registration closed: Disable registration is enabled under Admin panel > Authentication. Leave it that way as long as you’re the only one using 2FAuth. You can add other users manually; see below.
The One-Click App does not send emails. The Forgot your password? feature will say an email is on its way, but no email will arrive. Be sure to store your password securely and add a passkey as another way to log in.
If you still forget your password, you can reset it using the console. Connect to your VPS via SSH, use docker ps | grep twofauth to find the container name, then replace the container name, email address, and new password in the following command:
docker exec -e HOME=/tmp CONTAINERNAME php artisan tinker --execute='$u = App\Models\User::where("email", "admin@example.com")->firstOrFail(); $u->password = Illuminate\Support\Facades\Hash::make("NEW_PASSWORD"); $u->save(); echo "ok";'
If the command outputs ok, log in with your new password.
To check for a new version, go to the app settings (gear icon), select App update, and click Check for updates. Click Apply update to install a new version. The app will restart and be briefly unavailable. Your accounts will remain intact. 2FAuth also shows under Admin panel > App setup when a newer version has been released on GitHub. The One-Click App always installs the version we have approved, so the notice may appear there before it does in the ZapX Dashboard.
All data is stored in the app’s twofauth-data volume: the SQLite database containing your accounts, uploaded icons, and logs. Back up the volume by creating a backup of your VPS in the Backups tab. We also recommend exporting your data directly from 2FAuth; see “Export and Back Up Accounts” below. A server backup can only be restored if you also have the two automatically generated values from the app environment.
If you want to run 2FAuth yourself with Docker Compose, for example to use email delivery or custom settings, follow these steps.
- A VPS running Debian or Ubuntu with root access via SSH.
- Docker and Docker Compose; see the official Docker installation guide.
- A domain such as
2fa.example.comthat points to your VPS via DNS. HTTPS is required for passkeys and scanning QR codes with the camera.
| Minimum | Recommended | |
|---|---|---|
| CPU | 1 vCore | 1 vCore |
| RAM | 256 MB | 512 MB |
| Storage | 2 GB | 5 GB |
In this guide, 2FAuth listens only locally on port 8000. Only SSH and the web server that will later forward requests to 2FAuth are accessible from the outside:
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status
If you use the Network firewall in the ZapX Dashboard, open ports 80 and 443 there too. See Open Ports and Manage the Firewall on Linux.
Create a folder for 2FAuth. The image runs with user ID 1000, so this user must own the data folder:
mkdir -p /opt/2fauth/data
chown 1000:1000 /opt/2fauth/data
cd /opt/2fauth
Generate an app key that is exactly 32 characters long and save it in your password manager:
openssl rand -base64 24
Then create the file /opt/2fauth/docker-compose.yml and enter your key and domain:
services:
2fauth:
image: 2fauth/2fauth:latest
container_name: 2fauth
restart: unless-stopped
ports:
- "127.0.0.1:8000:8000"
volumes:
- ./data:/2fauth
environment:
- APP_NAME=2FAuth
- APP_KEY=YOUR_32_CHARACTER_KEY
- APP_URL=https://2fa.example.com
- APP_TIMEZONE=Europe/Berlin
- TRUSTED_PROXIES=*
- DB_CONNECTION=sqlite
- DB_DATABASE=/srv/database/database.sqlite
- MAIL_MAILER=log
- AUTHENTICATION_GUARD=web-guard
- WEBAUTHN_NAME=2FAuth
The important lines:
127.0.0.1:8000:8000makes 2FAuth accessible only from the server itself. External access is through the reverse proxy with HTTPS.APP_KEYencrypts sessions and protected data. Never change it after the first launch.APP_URLis the HTTPS address you’ll use. Passkeys only work if it matches the address in the browser.TRUSTED_PROXIES=*lets 2FAuth trust the headers from your reverse proxy. This is safe here because the port is only open locally.MAIL_MAILER=logwrites emails to the log only. To send emails, enter your SMTP server details (MAIL_MAILER=smtp,MAIL_HOST,MAIL_PORT,MAIL_USERNAME,MAIL_PASSWORD,MAIL_FROM_ADDRESS); see the list of environment variables.
Start 2FAuth:
docker compose up -d
docker compose logs -f
On first launch, 2FAuth creates the database. When no new lines appear, exit the log view with Ctrl+C.
With a manual installation, registration is initially open, and whoever registers first becomes the administrator. Create your account before 2FAuth is accessible through your domain, then close registration.
To do this, open an SSH tunnel to your VPS from your PC:
ssh -L 8000:127.0.0.1:8000 root@SERVER_IP
Then visit http://localhost:8000 in your browser, click Register, and create your account. Next, open Admin panel > Authentication from the menu and enable Disable registration. Set up the reverse proxy only after that.
To make 2FAuth available at a public address, put a web server such as nginx in front of it. A server block for 2fa.example.com looks like this:
server {
listen 80;
server_name 2fa.example.com;
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
See Set Up a Reverse Proxy with nginx for instructions on installing nginx and enabling the block. Get a free certificate with Certbot; see Create an SSL Certificate. 2FAuth will then be available at https://2fa.example.com.
All data is stored in /opt/2fauth/data. For a full backup, briefly stop 2FAuth so the SQLite database is in a consistent state:
cd /opt/2fauth
docker compose stop
tar czf /root/2fauth-backup-$(date +%F).tar.gz data docker-compose.yml
docker compose start
Include the docker-compose.yml file in the backup because it contains the app key. Without it, encrypted data is lost. Don’t store the backup only on the same server.
Before updating, read the release notes, make a backup, and then download the new image:
cd /opt/2fauth
docker compose pull
docker compose up -d
2FAuth handles any required database changes on startup. 2FAuth regularly releases security updates, so make sure to update promptly.
When you enable two-factor authentication for a service, it displays a QR code. In 2FAuth, click New to choose one of three options:
- Scan a QR code: Scan the code with your device’s camera. This only works over HTTPS.
- Upload a QR code: Upload a screenshot of the QR code; this is handy on a PC.
- Use the advanced form: Enter the service, account name, and secret key manually, then choose TOTP, HOTP, or STEAM.
2FAuth will then display the current code. Enter it on the service to finish setting up two-factor authentication. Use groups and icons to keep track of your accounts, even when you have many.
Under New > Import, 2FAuth can import accounts from other apps. Supported formats include Google Authenticator (as an export QR code), Aegis, 2FAS, FreeOTP+, Bitwarden, and exports from 2FAuth itself. Export the accounts from the old app without password protection or encryption, otherwise 2FAuth won’t be able to read the file. Delete the export file afterward, as it contains your secrets in plain text.
Under Admin panel > Users, you can see all users. To let someone create their own account, briefly enable registration under Admin panel > Authentication. Use Restrict registration to allow registration only for specific email addresses. Then enable Disable registration again. Each user can only see their own accounts unless you specifically share accounts with them.
Under Manage, select accounts and export them with Export. The 2FAuth format is suitable for backups that you may want to import later, while almost all authenticator apps support the otpauth URIs format. Store the export encrypted, for example as an attachment in your password manager.
- No email: Password recovery, email-based account recovery, and notifications don’t work. If you need these features, use the manual installation with your own SMTP server.
- No offline access: You can’t see your codes without a connection to your VPS. Keep the recovery codes for your most important services handy.
- Fixed version: You can update the One-Click App using App update, but you can’t choose a specific version there.
With 2FAuth, you can access your two-factor codes on all your devices without entrusting them to a cloud provider. The quickest and safest way to get started is with the One-Click App: your administrator account is created before the first visit, and registration is closed. Then enable encryption, add a passkey, and store the automatically generated values together with your backups. If you need email delivery or custom settings, choose the manual installation with Docker Compose.
