megatools-2fa(1)
================

NAME
----
megatools 2fa - Manage two-factor authentication of a mega.nz account


SYNOPSIS
--------
[verse]
'megatools 2fa' [--scripted]
'megatools 2fa' [--scripted] --setup
'megatools 2fa' [--scripted] --enable <code>
'megatools 2fa' [--scripted] --disable <code>


DESCRIPTION
-----------

Shows whether two-factor authentication (2FA) is enabled for the account,
and enables or disables it.

mega.nz implements 2FA with time based one-time codes (TOTP, RFC 6238: 6
digits, a new code every 30 seconds) generated by an authenticator app from
a secret shared with the server. Enabling it takes two steps: '--setup' asks
the server for a new secret, which you add to the app, and '--enable' with
the current code from the app turns 2FA on.

With 2FA enabled, every new login needs a code. Megatools keeps the session
in its cache, so a code is only needed when the cached session expires or
is removed. The code can be given with '--2fa-code', generated by megatools
from the secret ('--2fa-secret' or 'TwoFactorSecret' in the config file),
or typed in when megatools asks for it on a terminal. The server accepts
each code only once, and codes up to about a minute old.

If you lose the authenticator app, you can only get into the account with
its recovery key. Make sure you have it before enabling 2FA (mega.nz
webclient: Settings, Security, Recovery key).


OPTIONS
-------

--setup::
	Request a new secret from the server and print it, also as an
	'otpauth://' URI that can be turned into a QR code. Running it again
	replaces the secret that wasn't enabled yet. The secret is base32,
	upper or lower case, spaces don't matter.

--enable <code>::
	Enable 2FA with a code generated from the secret printed by '--setup'.

--disable <code>::
	Disable 2FA. The code is generated from the current secret.

--scripted::
	Print only the secret for '--setup', 'enabled' or 'disabled' for the
	status, and nothing on success of '--enable' and '--disable'.

Without '--setup', '--enable' or '--disable', the 2FA status is shown.

include::auth-options.txt[]
include::basic-options.txt[]


EXAMPLES
--------

* Enable 2FA:
+
------------
$ megatools 2fa --setup
Add this secret to your authenticator app:

  mx4rnl77wk2zrm4l36u67r5glifkkafd5ih4nvc5t2x5ln2drfqa

or as a URI (for a QR code):

  otpauth://totp/MEGA:your@email?secret=mx4rnl77wk2zrm4l36u67r5glifkkafd5ih4nvc5t2x5ln2drfqa&issuer=MEGA

Then enable two-factor authentication with a code from the app:

  megatools 2fa --enable <code>

Keep the secret private, together with the password it can be used to log in.
$ megatools 2fa --enable 123456
Two-factor authentication is enabled. Logins now need a code from the
...
------------


* Show the status, and disable 2FA:
+
------------
$ megatools 2fa
Two-factor authentication is enabled.
$ megatools 2fa --disable 654321
Two-factor authentication is disabled.
------------


* Show a QR code for the app in the terminal (with qrencode):
+
------------
$ megatools 2fa --setup | grep otpauth: | qrencode -t ansiutf8
------------

* Use the secret from the config file to log in without being asked for a
  code (see man:megarc[5]):
+
------------
[Login]
Username = your@email
Password = yourpassword
TwoFactorSecret = mx4rnl77wk2zrm4l36u67r5glifkkafd5ih4nvc5t2x5ln2drfqa
------------


include::footer.txt[]
