1) First of all simply visit the link below and sign in to your account, it will straight away open the profile information page to edit details.
2) Click on set up your second sign-in verification beta option as shown below.
3 ) On the next page check the box to turn on the second sign-in verifcation for your Yahoo account. After that it will show a pop-up that if you wish to select an existing phone number in your profile or would like to use a new one.
4 ) On the next screen you will see the confirmation message, by default it selects the first option but I recommend to select the second one which is only your mobile number can be used for verification.
5 ) If you or someone else sign-in from an unrecognized device then after typing the username and password, it asks for the verifcation code that can be received on your mobile or email.
If you do not use Yahoo as your primary email provider but you hold an account on it to use their Messenger service then it is strongly recommended to turn on the second authentication feature that too on mobile. If you setup the same for a third party email provider and have not set up the two-step verification for that email where you have chosen to receive the code for your Yahoo account and there is a keylogger in your computer then your other email account can also be compromised along with Yahoo.