two-factor authentication
Two-factor authentication is an extra layer of security for your Apple ID designed to ensure that you’re the only person who can access your account, even if someone knows your password.
To see whether your Apple ID has two-factor authentication turned on, choose Apple menu > System Preferences, click Apple ID, then select Password & Security in the sidebar.
You can also turn two-factor authentication on and manage your trusted devices and phone numbers by signing in to your Apple ID account page.
Enroll in two-factor authentication
If your account meets all the requirements for two-factor authentication, you are prompted to turn it on when you first use your Mac.
Important: If you’re using two-step verification, you must turn it off before you can turn on two-factor authentication. To do so, sign in to your Apple ID account page. In the Security section, click Edit, then click Turn Off Two-Step Verification. You’re asked to create new security questions and verify your date of birth. You should receive an email confirming that two-step verification for your Apple ID is turned off.
Use two-factor authentication
Once enrolled, when you enter your Apple ID and password for the first time on a new device, you’re asked to verify your identity with a six-digit verification code. This code is displayed automatically on your other devices or sent to a phone number you trust. Just enter the code to sign in and access your information on your new device.
You won’t be asked for a verification code again on that device unless you sign out of iCloud completely, erase your device, or need to change your password for security reasons.
See the Apple Support article Two-factor authentication for Apple ID.