doc/user/profile/account/create_accounts.md
{{< details >}}
{{< /details >}}
User accounts form the foundation of GitLab collaboration. Every person who needs access to your GitLab projects requires an account. User accounts control access permissions, track contributions, and maintain security across your instance.
You can create user accounts in GitLab in different ways:
You can also use the users API endpoint to automatically create users.
Choose the right method based on your organization's size, security requirements, and workflows.
By default, any user visiting your GitLab instance can register for an account. If you have previously disabled this setting, you must turn it back on.
Users can create their own accounts by either:
https://gitlab.example.com/users/sign_up).Prerequisites:
To create a user:
GitLab sends an email to the user with a sign-in link, and the user must create a password when they first sign in. You can also directly set a password for the user.
GitLab can automatically create user accounts through authentication integrations. Users are created when they:
allow_single_sign_on turned on{{< details >}}
{{< /details >}}
[!warning] Commands that change data can cause damage if not run correctly or under the right conditions. Always run commands in a test environment first and have a backup instance ready to restore.
To create a user through the Rails console:
Start a Rails console session.
Run the command according to your GitLab version:
{{< tabs >}}
{{< tab title="16.10 and earlier" >}}
u = User.new(username: 'test_user', email: '[email protected]', name: 'Test User', password: 'password', password_confirmation: 'password')
# u.assign_personal_namespace
u.skip_confirmation! # Use only if you want the user to be automatically confirmed. If you do not use this, the user receives a confirmation email.
u.save!
{{< /tab >}}
{{< tab title="16.11 through 17.6" >}}
u = User.new(username: 'test_user', email: '[email protected]', name: 'Test User', password: 'password', password_confirmation: 'password')
u.assign_personal_namespace(Organizations::Organization.default_organization)
u.skip_confirmation! # Use only if you want the user to be automatically confirmed. If you do not use this, the user receives a confirmation email.
u.save!
{{< /tab >}}
{{< tab title="17.7 and later" >}}
u = Users::CreateService.new(nil,
username: 'test_user',
email: '[email protected]',
name: 'Test User',
password: '123password',
password_confirmation: '123password',
organization_id: Organizations::Organization.first.id,
skip_confirmation: true
).execute
[!note] If you have disabled new user accounts, you must run this command as an administrator. In the previous command, replace
Users::CreateService.new(nil,withUsers::CreateService.new(User.find_by(admin: true),
{{< /tab >}}
{{< /tabs >}}