# DirectAdmin Two-Step Authentication: Can You Force It? Audit Script (Tested)

Source: https://srvscripts.com/guides/directadmin-force-two-step-authentication/
Updated: 2026-11-02
Publisher: srvScripts (https://srvscripts.com/)

**Short answer:** DirectAdmin two-step authentication cannot be made mandatory on 1.712, because there is no setting that forces every account to use it: `twostep_auth=1` only makes the feature available, and each account turns it on for itself. What you can do is audit who has it (each account’s `user.conf` has `twostep_auth=yes` plus a `twostep_auth_secret.txt` file), chase the admin and reseller accounts that do not, and limit who can reach port 2222. (Reviewed October 2026.)

In short: DirectAdmin two-step authentication cannot be made mandatory on 1.712, because there is no setting that forces every account to use it: twostep_auth=1 only makes the feature available, and each account turns it on for itself. What you can do is…

“Force two-step authentication for all users” is a common DirectAdmin forum request. We looked through the 1.712 settings and API for an enforcement option, turned two-step login on and off for a test account through the API, and wrote a read-only audit script from what changed on disk.

## What DirectAdmin 1.712 offers

| Setting or feature | What it does |
| --- | --- |
| twostep_auth=1 (directadmin.conf) | Makes two-step login available to accounts. It does not require it. |
| twostep_auth_trust_days=30 | How long a browser can be trusted after a successful code. |
| notify_on_all_twostep_auth_failures (user.conf) | Per-account: send a notice for every failed code. |
| /api/multi-factor-auth/... | The account’s own endpoints: generate a secret, enable, disable, recovery codes. |

We found no configuration key (see DirectAdmin’s [list of directadmin.conf values](https://docs.directadmin.com/directadmin/general-usage/all-directadmin-conf-values.html)), package option or admin API call that makes two-step login mandatory: `da config` lists only the two keys above, and the panel binary contains no other two-step setting. Treat enforcement as a process, not a switch: audit, ask, and restrict access until it is done.

## How two-step login shows up on disk

We enabled two-step login for our test admin through the API (generate a secret, then send a valid code to `POST /api/multi-factor-auth/enable` as `{"otp":"123456"}`) and watched the account folder:

| State | user.conf | Secret file |
| --- | --- | --- |
| Off (default) | twostep_auth=no | none |
| Secret generated, not confirmed | twostep_auth=no | twostep_auth_secret.txt created (600, diradmin) |
| On | twostep_auth=yes | twostep_auth_secret.txt present |
| Turned off again (/api/multi-factor-auth/disable) | twostep_auth=no | removed |

A request with the wrong field name (`code` instead of `otp`) returned `OTP_INVALID_CODE` and changed nothing. Login keys kept working for API calls after two-step login was turned on, so audit login keys separately: they are not covered by the second step.

## DirectAdmin two-step authentication audit script

This prints every account with its type and two-step state. It exits 1 if an admin or reseller account does not have it on (with `--all`, users count too), and 3 if it could not read something, so a monitoring check never mistakes a read problem for “all good”. An account whose type it does not recognise is treated like an admin. It only reads files; `DA_USERS_DIR` lets you point it at a copy for testing.

```
#!/bin/bash
# da-2fa-audit.sh - list DirectAdmin accounts and whether two-step login is on. Read-only, run as root.
# Exit: 0 all required accounts on, 1 an admin/reseller (or, with --all, any) account is off,
#       3 something could not be read.
set -u
ALL=0; [ "${1:-}" = "--all" ] && ALL=1
D=${DA_USERS_DIR:-/usr/local/directadmin/data/users}
[ "$(id -u)" = 0 ] || { echo "UNKNOWN: run as root"; exit 3; }
[ -d "$D" ] || { echo "UNKNOWN: $D not found"; exit 3; }
need=0; unknown=0; n=0
printf '%-16s %-9s %-9s %s\n' ACCOUNT TYPE 2FA NOTE
for dir in "$D"/*/; do
  [ -d "$dir" ] || continue
  u=$(basename "$dir"); conf="${dir}user.conf"; n=$((n+1))
  if [ ! -r "$conf" ]; then
    printf '%-16s %-9s %-9s %s\n' "$u" "?" UNKNOWN "user.conf missing or unreadable"; unknown=1; continue
  fi
  type=$(awk -F= '$1=="usertype"{print $2; exit}' "$conf")
  tsa=$(awk -F= '$1=="twostep_auth"{print $2; exit}' "$conf")
  susp=$(awk -F= '$1=="suspended"{print $2; exit}' "$conf")
  note=""
  case "$tsa" in
    yes) if [ -s "${dir}twostep_auth_secret.txt" ]; then st=on; else st=BROKEN; note="enabled but no secret file"; fi ;;
    no)  st=off; [ -e "${dir}twostep_auth_secret.txt" ] && note="secret generated, not confirmed" ;;
    "")  st=off; note="twostep_auth not set" ;;
    *)   st=UNKNOWN; note="twostep_auth=$tsa"; unknown=1 ;;
  esac
  case "$type" in
    admin|reseller) req=1 ;;
    user) req=$ALL ;;
    *) req=1; note="${note:+$note, }usertype '${type}' not recognised"; unknown=1 ;;
  esac
  [ "$susp" = "yes" ] && note="${note:+$note, }suspended"
  case "$st" in off|BROKEN) [ "$req" = 1 ] && need=1 ;; esac
  printf '%-16s %-9s %-9s %s\n' "$u" "${type:-?}" "$st" "$note"
done
[ "$n" -gt 0 ] || { echo "UNKNOWN: no accounts found in $D"; exit 3; }
[ "$need" = 1 ] && exit 1
[ "$unknown" = 1 ] && exit 3
exit 0
```

Results on our server, 20 and 21 October 2026: with two-step login on, `admin  admin  on` and exit code 0; with the secret file moved aside, `BROKEN` and exit 1; after turning it off through the API, `off` and exit 1. Against test copies of the account folder it reported a reseller and an admin as on with a user off (exit 0, and exit 1 with `--all`), a confirmed-but-missing secret as `BROKEN`, an unconfirmed secret as `off` with a note, an unexpected `twostep_auth` value and a missing `user.conf` as `UNKNOWN` (exit 3), an empty folder and a non-root run as exit 3. Run it from root’s cron weekly and mail yourself the output, or feed the exit code to your monitoring.

## Closing the gap until everyone has it on

- **Start with admins and resellers.** They can change other accounts. The script fails on them by default.

- **Restrict port 2222.** If staff connect from known networks or a VPN, allow the panel port only from those in the firewall. That protects every account, with or without a second step.

- **Keep the brute-force scanner on.** On our server `brute_force_log_scanner=1` was the default; check it with `da config | grep ^brute_force_log_scanner`.

- **Review login keys.** Remove keys nobody uses and limit the rest to the commands and IP addresses they need.

- **Ask users directly.** Send each account without two-step login a short how-to for their panel’s security settings and re-run the audit a week later.

If you need hard enforcement for all users, check the changelog of each new release; we will update this page if a setting appears.

## How we tested

- Server: DirectAdmin 1.712 on AlmaLinux 9.8, 20 October 2026. The licence allowed one account, so all tests used the admin account.

- Two-step login turned on through `/api/multi-factor-auth/otp/generate-secret` and `/api/multi-factor-auth/enable` with a code calculated from the secret (the secret was never printed), then turned off with `/api/multi-factor-auth/disable`. The script was run in each state and once with the secret file moved aside.

- Not tested: real reseller and user accounts (licence limit; the script was checked against test copies of their files), the panel’s own enable screen, recovery codes and the trusted-browser period.

## FAQ

### Can I force all DirectAdmin users to use two-step authentication?

Not with a setting on DirectAdmin 1.712. Use the audit script to find accounts without it and restrict panel access by IP until they turn it on.

### Where does DirectAdmin store the two-step secret?

In `/usr/local/directadmin/data/users/USER/twostep_auth_secret.txt` (mode 600, owner diradmin), with `twostep_auth=yes` in the same folder’s `user.conf`.

### Do DirectAdmin login keys need the two-step code?

No. Our API calls with a login key kept working after two-step login was turned on, so manage login keys separately.

### How do I turn two-step login off for a locked-out user?

The account’s own API has `POST /api/multi-factor-auth/disable`, which turned it off on our server when called with that account’s login key. We did not test the panel’s Login As route for this. Ask for proof of identity first.

Related: [the da CLI (config-get and config-set)](https://srvscripts.com/guides/directadmin-da-cli/) and [DirectAdmin’s /api/ endpoints](https://srvscripts.com/guides/directadmin-removed-api-endpoints/).
