Failed to set user configuration: The security code is invalid. – SOLVED

When configuring 2FA (Two Factor Authentication) in WHM or cPanel you might receive the following error: Failed to set user configuration: The security code is invalid.

If you are certain you are entering the correct code, then it is very likely that the time on the device issuing your code is incorrect. We use Google Authenticator on Android, and it turned out the time on the phone was incorrect. Once you change the settings to get the time automatically everything will work as expected with 2FA.