2021-01-29 00:20:46 +05:30
---
2021-03-11 19:13:27 +05:30
stage: Enablement
group: Distribution
2021-02-22 17:27:13 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2021-01-29 00:20:46 +05:30
---
2021-03-11 19:13:27 +05:30
# User management **(FREE SELF)**
2020-05-24 23:13:21 +05:30
GitLab provides Rake tasks for user management.
2014-09-02 18:07:02 +05:30
## Add user as a developer to all projects
2020-05-24 23:13:21 +05:30
To add a user as a developer to all projects, run:
2020-03-13 15:44:24 +05:30
```shell
2014-09-02 18:07:02 +05:30
# omnibus-gitlab
sudo gitlab-rake gitlab:import:user_to_projects[username@domain.tld]
2015-04-26 12:48:37 +05:30
# installation from source
bundle exec rake gitlab:import:user_to_projects[username@domain.tld] RAILS_ENV=production
2014-09-02 18:07:02 +05:30
```
## Add all users to all projects
2020-05-24 23:13:21 +05:30
To add all users to all projects, run:
2014-09-02 18:07:02 +05:30
2020-03-13 15:44:24 +05:30
```shell
2014-09-02 18:07:02 +05:30
# omnibus-gitlab
sudo gitlab-rake gitlab:import:all_users_to_all_projects
2015-04-26 12:48:37 +05:30
# installation from source
bundle exec rake gitlab:import:all_users_to_all_projects RAILS_ENV=production
2014-09-02 18:07:02 +05:30
```
2020-05-24 23:13:21 +05:30
Admin users are added as maintainers.
2014-09-02 18:07:02 +05:30
## Add user as a developer to all groups
2020-05-24 23:13:21 +05:30
To add a user as a developer to all groups, run:
2020-03-13 15:44:24 +05:30
```shell
2014-09-02 18:07:02 +05:30
# omnibus-gitlab
sudo gitlab-rake gitlab:import:user_to_groups[username@domain.tld]
2015-04-26 12:48:37 +05:30
# installation from source
bundle exec rake gitlab:import:user_to_groups[username@domain.tld] RAILS_ENV=production
2014-09-02 18:07:02 +05:30
```
## Add all users to all groups
2020-05-24 23:13:21 +05:30
To add all users to all groups, run:
2014-09-02 18:07:02 +05:30
2020-03-13 15:44:24 +05:30
```shell
2014-09-02 18:07:02 +05:30
# omnibus-gitlab
sudo gitlab-rake gitlab:import:all_users_to_all_groups
2015-04-26 12:48:37 +05:30
# installation from source
bundle exec rake gitlab:import:all_users_to_all_groups RAILS_ENV=production
2014-09-02 18:07:02 +05:30
```
2015-09-11 14:41:01 +05:30
2021-02-22 17:27:13 +05:30
Administrators are added as owners so they can add additional users to the group.
2020-05-24 23:13:21 +05:30
2021-02-22 17:27:13 +05:30
## Update all users in a given group to `project_limit:0` and `can_create_group: false`
To update all users in given group to `project_limit: 0` and `can_create_group: false` , run:
```shell
# omnibus-gitlab
sudo gitlab-rake gitlab:user_management:disable_project_and_group_creation\[:group_id\]
# installation from source
bundle exec rake gitlab:user_management:disable_project_and_group_creation\[:group_id\] RAILS_ENV=production
```
It updates all users in the given group, its subgroups and projects in this group namespace, with the noted limits.
## Control the number of billable users
2015-09-11 14:41:01 +05:30
2020-05-24 23:13:21 +05:30
Enable this setting to keep new users blocked until they have been cleared by the administrator.
Defaults to `false` :
2015-09-11 14:41:01 +05:30
2020-04-22 19:07:51 +05:30
```plaintext
2015-09-11 14:41:01 +05:30
block_auto_created_users: false
```
2015-10-24 18:46:33 +05:30
2020-05-24 23:13:21 +05:30
## Disable two-factor authentication for all users
2015-10-24 18:46:33 +05:30
2020-05-24 23:13:21 +05:30
This task disables two-factor authentication (2FA) for all users that have it enabled. This can be
2021-02-22 17:27:13 +05:30
useful if the GitLab `config/secrets.yml` file has been lost and users are unable
2020-05-24 23:13:21 +05:30
to log in, for example.
To disable two-factor authentication for all users, run:
2015-10-24 18:46:33 +05:30
2020-03-13 15:44:24 +05:30
```shell
2015-10-24 18:46:33 +05:30
# omnibus-gitlab
sudo gitlab-rake gitlab:two_factor:disable_for_all_users
# installation from source
bundle exec rake gitlab:two_factor:disable_for_all_users RAILS_ENV=production
```
2016-11-03 12:29:30 +05:30
2020-05-24 23:13:21 +05:30
## Rotate two-factor authentication encryption key
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
GitLab stores the secret data required for two-factor authentication (2FA) in an encrypted
database column. The encryption key for this data is known as `otp_key_base` , and is
2017-09-10 17:25:29 +05:30
stored in `config/secrets.yml` .
If that file is leaked, but the individual 2FA secrets have not, it's possible
to re-encrypt those secrets with a new encryption key. This allows you to change
the leaked key without forcing all users to change their 2FA details.
2020-05-24 23:13:21 +05:30
To rotate the two-factor authentication encryption key:
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
1. Look up the old key. This is in the `config/secrets.yml` file, but **make sure you're working
2021-02-22 17:27:13 +05:30
with the production section**. The line you're interested in looks like this:
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
```yaml
production:
2021-02-22 17:27:13 +05:30
otp_key_base: fffffffffffffffffffffffffffffffffffffffffffffff
2020-05-24 23:13:21 +05:30
```
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
1. Generate a new secret:
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
```shell
# omnibus-gitlab
sudo gitlab-rake secret
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
# installation from source
bundle exec rake secret RAILS_ENV=production
```
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
1. Stop the GitLab server, back up the existing secrets file, and update the database:
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
```shell
# omnibus-gitlab
sudo gitlab-ctl stop
sudo cp config/secrets.yml config/secrets.yml.bak
sudo gitlab-rake gitlab:two_factor:rotate_key:apply filename=backup.csv old_key=< old key > new_key=< new key >
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
# installation from source
sudo /etc/init.d/gitlab stop
cp config/secrets.yml config/secrets.yml.bak
bundle exec rake gitlab:two_factor:rotate_key:apply filename=backup.csv old_key=< old key > new_key=< new key > RAILS_ENV=production
```
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
The `<old key>` value can be read from `config/secrets.yml` (`< new key > ` was
2021-02-22 17:27:13 +05:30
generated earlier). The **encrypted** values for the user 2FA secrets are
2020-05-24 23:13:21 +05:30
written to the specified `filename` . You can use this to rollback in case of
error.
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
1. Change `config/secrets.yml` to set `otp_key_base` to `<new key>` and restart. Again, make sure
you're operating in the **production** section.
2017-09-10 17:25:29 +05:30
2020-05-24 23:13:21 +05:30
```shell
# omnibus-gitlab
sudo gitlab-ctl start
# installation from source
sudo /etc/init.d/gitlab start
```
2017-09-10 17:25:29 +05:30
If there are any problems (perhaps using the wrong value for `old_key` ), you can
restore your backup of `config/secrets.yml` and rollback the changes:
2020-04-08 14:13:33 +05:30
```shell
2017-09-10 17:25:29 +05:30
# omnibus-gitlab
sudo gitlab-ctl stop
sudo gitlab-rake gitlab:two_factor:rotate_key:rollback filename=backup.csv
sudo cp config/secrets.yml.bak config/secrets.yml
sudo gitlab-ctl start
# installation from source
sudo /etc/init.d/gitlab start
bundle exec rake gitlab:two_factor:rotate_key:rollback filename=backup.csv RAILS_ENV=production
cp config/secrets.yml.bak config/secrets.yml
sudo /etc/init.d/gitlab start
```