Petter Holt Juliussen • Mail | Mastodon | GitHub | Letterboxd

for later reference.

User management


Root login

The root user is the administrative user in a Linux environment that has very broad privileges. Because of the heightened privileges of the root account, you are actually discouraged from using it on a regular basis. This is because part of the power inherent with the root account is the ability to make very destructive changes, even by accident.

The next step in a setup process is to set up an alternative user account with a reduced scope of influence for day-to-day work.

Create new user

Once you are logged in as root, we're prepared to add the new user account that we will use to log in from now on.

adduser sammy

Now, we have a new user account with regular account privileges.

useradd - create a new user or update default new user information
When invoked without the -D option, the useradd command creates a new user account using the 
values specified on the command line plus the default values from the system. Depending on 
command line options, the useradd command will update system files and may also create the 
new user's home directory and copy initial files.

By default, a group will also be created for the new user (see -g, -N, -U, and USERGROUPS_ENAB).
useradd [options] LOGIN
useradd -D
useradd -D [options]
-D, --defaults
When invoked with only the -D option, useradd will display the current default values. When 
invoked with -D plus other options, useradd will update the default values for the specified 

Man: adduser

Root privileges

To avoid having to log out of our normal user and log back in as the root account when performing administrative tasks, we can set up what is known as "superuser" or root privileges for our normal account. This will allow our normal user to run commands with administrative privileges by putting the word sudo before each command.

To add these privileges to our new user, we need to add the new user to the "sudo" group. By default, on Ubuntu 16.04, users who belong to the "sudo" group are allowed to use the sudo command. As root, run this command to add the user to the sudo group:

usermod -aG sudo sammy

usermod - modify a user account
The usermod command modifies the system account files to reflect the changes that are specified 
on the command line.
usermod [options] LOGIN
-a, --append
Add the user to the supplementary group(s). Use only with the -G option.

-G, --groups GROUP1[,GROUP2,...[,GROUPN]]]
A list of supplementary groups which the user is also a member of. Each 
group is separated from the next by a comma, with no intervening 
whitespace. The groups are subject to the same restrictions as the group 
given with the -g option.

If the user is currently a member of a group which is not listed, the 
user will be removed from the group. This behaviour can be changed via 
the -a option, which appends the user to the current supplementary 
group list.

Man: usermod