How to add an attribute to a user?

The easiest trick is to use the user_contactmethods – the fields don’t actually have to be contacts, but WordPress will do all the leg work for you (displaying the fields & saving the data):

function wpse_183763_user_contactmethods( $methods, $user ) {
    $methods['my_field_1'] = 'My Label For Field 1';
    $methods['my_field_2'] = 'My Label For Field 2';

    return $methods;
}

add_filter( 'user_contactmethods', 'wpse_183763_user_contactmethods', 10, 2 );

If you add this code to a plugin or your functions.php, you’ll see the new fields when editing your profile. To get the values, just use the meta API:

// With a user ID
echo get_user_meta( $user_id, 'my_field_1', true );

// Or with a WP_User object
echo $user->my_field_1;