Add fields to user from a custom module
Base fields

You can add base fields to the user entity in a hook:

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
/**
 * Implements hook_entity_base_field_info().
 */
function mymodule_entity_base_field_info(EntityTypeInterface $entity_type) {
  if ($entity_type-&gt;id() === 'user') {
    $fields['field1'] = BaseFieldDefinition::create('text')
      -&gt;setLabel(t('New field 1'))
      -&gt;setTranslatable(TRUE);
    return $fields;
  }
}


Bundle fields

But most times you probably want to use bundle fields, which can be added and modified in UI and can be easily deployed through configuration. In D8 the user entity is fieldable like nodes.

See this tutorial:

Programming custom fields into your content type

You can apply the same procedure to users. Replace node with user, also the content type with user, because the user entity has no bundles and then you use the entity name as replacement.

In a standard install user_picture is the only user field configured out-of-the-box, which you can use as an example: 

field.field.user.user.user_picture.yml


You can see that user is twice in the config name, for the entity type and the bundle name.

How to add the fields

The easiest way to implement this in a custom module is to add the fields in UI

/admin/config/people/accounts/fields


and then export the configured fields:

/admin/config/development/configuration


If you export the complete configuration before and after you've added the fields you can make a diff to catch all new yaml files.

Put the new configuration files in /config/install of your module. Remove the uuid line from the exported yaml files.