Skip to content

Instantly share code, notes, and snippets.

@ergoz
Forked from lpsm-dev/main.rb
Last active May 23, 2025 16:53
Show Gist options
  • Save ergoz/dba4ea67b7aeb84104f662f4f026be8f to your computer and use it in GitHub Desktop.
Save ergoz/dba4ea67b7aeb84104f662f4f026be8f to your computer and use it in GitHub Desktop.
[GitLab] - Create Admin user in Rails Console
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!
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!

how to run

docker exec -it <container-id> gitlab-rails console
# Example with a two-line Ruby script
sudo gitlab-rails runner "user = User.first; puts user.username"

# Example with a ruby script file (make sure to use the full path)
sudo gitlab-rails runner /path/to/script.rb

user = User.new(username: 'user', email: '[email protected]', name: 'user', password: 'user', password_confirmation: 'user')
# Use it only if you wish user to be automatically confirmed. If skipped, user receives confirmation e-mail
user.skip_confirmation!
user.admin = true
user.save!
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,
admin: true
).execute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment