Users and Groups
Users and Groups
$ whoami
mateo
The root user is the main user account on the system with all of the
permissions (like an administrator account). Since this account has unlimited
capabilities, it is often recommended not to use it directly, so that we don't do
something irreversible to the system. Instead, you can use the sudo command.
When you prepend a command with sudo that means that you want to execute
it as the root user. However, the requirement for using it is that your user
account is a part of the sudo group.
groups command will list you all of the groups that you are a part of. All of the
possible groups on the system can be seen in the /etc/group file.
To see the user ID and all of the user groups, you can also use the id command.
To create a new user we can use the useradd command. There is also a
adduser command on most of the Linux systems, which is more beginner
friendly. It will ask you for the finger information (information about the user).
However in this course we will use the good old useradd option, which always
and definitely works.
m options gives this user a home directory. d option will define where that
directory will be created and its name.
s option defines the default login shell. If you don't know where the shell is
installed, use the which command followed by the name of the shell command.
You can also edit the user configuration later with the usermod command.
Set a login password on a user john with the sudo passwd john command.
You can set a password exparation time with the chage command.
All of the users passwords are stored in the hashed format, inside of the
/etc/shadow file.
We can create groups with the addgroup and delete them with the delgroup
command.
The command above will add the user john to the sudo group. You can add
users to the group with the usermod command that has the aG options.
To login as another user, use the su command.
$ su - john
This will log you into the john user account. To logout you can use the exit
command.
On macOs you can add users from the graphical interface. Go to the System
Preferences > Users & Groups and from there you can add new users.