GitLab Authenticator Lost but SSH Still Works: Regenerate Recovery Codes

Published: · Updated:
Share

After losing a GitLab authenticator, inspect the recovery resources still available. If a computer still holds the private key matching an SSH public key previously registered to the account, GitLab documents a way to regenerate recovery codes. This requires the original matching private key and its existing registration relationship. Establish the account, instance and original key before replacing any saved recovery material.

Separate an existing code from regeneration

If you already saved an unused recovery code, normal sign-in can use it after the username or email and password. Choose Recover your account on the two-factor screen, enter the value and select Verify code. Each code works once, while the other unused codes remain valid. That is different from creating a completely new list over SSH.

Regeneration invalidates the previous list. Identify which GitLab site and identity your saved material belongs to, particularly when a company instance and GitLab.com have similar usernames. If a web session remains usable, the documented settings route can also regenerate codes; preserve that session while choosing the route matching your actual resources.

Check the original key and deployment

The SSH procedure requires access to the private key corresponding to the account’s registered public key. GitLab specifically says deployments using gitlab-sshd cannot use it for regeneration. For a self-managed instance, use its actual server hostname and ask the responsible administrator about deployment support when necessary. An unsupported command and an incorrect key are different problems.

Keep the original private key on your controlled device and use it in your own terminal. Compare its matching public key with the original account registration, then load that existing key for authentication. Recovery relies on that earlier established relationship.

Generate the replacement from your own terminal

  1. Check that the SSH agent is running, using the official instructions appropriate to macOS/Linux or Windows.
  2. Load the original private key into the agent. On macOS/Linux, the documented ssh-add command takes your actual private-key file path rather than literal placeholder text.
  3. For GitLab.com, run ssh git@gitlab.com 2fa_recovery_codes. Replace the hostname with the real server for a self-managed instance.
  4. Read the confirmation and enter yes only when you intend to replace the recovery-code set.
  5. Save the newly generated list securely and mark the earlier list as replaced and unusable.
  6. Return to sign-in with the original username or email and password, select Recover your account and verify with a new recovery code.

GitLab Authenticator Lost but SSH Still Works: Regenerate Recovery Codes

After the terminal generates the list, complete the separate website sign-in using a new code and inspect its actual acceptance. Keep the site and identity matched through both stages. After access, GitLab instructs you to set up two-factor authentication immediately with a new device. Finish that arrangement rather than relying indefinitely on the remaining backup values.

Investigate key loading before deleting resources

GitLab connects Permission denied (publickey) during recovery-code generation with a non-default SSH-key file path. Its troubleshooting direction is to configure SSH through the agent to use the relevant directory. Inspect the selected file and account relationship instead of deleting the original key or describing the error as missing SMS.

If the authenticator is still available and the actual error is invalid pin code, the documentation has a separate device-time-synchronization branch. When the app remains available, complete that time check before deciding on regeneration. Select a route according to whether the resource is lost or still available to correct, rather than treating one rejected response as proof that all enrollment must be erased.

Know the limits of the remaining support route

An authenticator backup can help only if its backup feature was enabled beforehand. Use the authenticator provider’s own help for its backup recovery. When the documented resources do not work, GitLab.com’s support-assisted two-factor reset is limited to subscription accounts; support cannot reset a Free account’s factor. Self-managed users should contact their own administrator instead of importing another offering’s support eligibility.

End by checking original-account access, a working replacement factor and safe access to the current recovery list. A missing project after sign-in requires a membership or permission check: inspect that project’s membership and organization requirements separately. A support description can identify the instance, error and last completed action without publishing the private key, enrollment secret or recovery codes.

Related questions

GitLab instances and authenticators: Check the site, original identity and expected code source first.

FACEIT authenticator recovery: Inventory the recovery resources still available.

Namecheap backup-code setup: Check authenticator setup after replacing an earlier code set.

References

GitLab Docs — Troubleshooting two-factor authentication

Sources checked on 2026-11-26.

Related Articles

Need help?

Click here and start chatting with us!