create users

password, groups and stuff

September 20, 2022



Add a new user and set the user password.

If you want to create a user and set a password for the user right away, it is best to:

# Create user 'test_user' without home directory.
$ sudo useradd --no-create-home --shell /bin/bash test_user
# Add a password.
$ sudo passwd test_user

useradd has the option -p, --password. However - according to man useradd - there is a good reason not to use this option:

# Taken from 'man useradd'.
...
The encrypted password, as returned by crypt(3). The default is to disable the password.

Note: This option is not recommended because the password (or encrypted password) will be visible by users listing the
processes.
...

Note:

Add a user to a group

Assuming user and group already exist.

# Add the user to the group.
$ sudo usermod --append --groups docker main_user

To make the change take effect, you need to log out and in once.

Another option is to open a new shell session, for example in bash:

# Open new 'bash' session.
$ bash

To add the current user to the group for the duration of the current session:

$ newgrp docker