tags:
- linux
- software
- operating-system
source: https://www.makeuseof.com/user-management-linux-guide/
created: 2024-10-20
published: 2022-01-11
...
What should every user who utilizes your Linux machine have?
Every user who utilizes your Linux machine should have a separate user account.
What does having a separate user account allow each user to do?
Having a separate user account allows a user to have separate files in a safe space and the ability to customize their home directory, path, environment variables, and more.
How do you list the available user accounts on Linux?
To list the available user accounts on Linux, run:
cut -d: -f1 /etc/passwd
Which program do you use to add a new user account to the system?
The program you use to add a new user account to the system is useradd
.
What are some of the flags for the
useradd
command?
Some of the flags for theuseradd
command include:
-c
- Adds a description or comment.-d
- Sets the home directory path.-g
- Sets the primary group.-G
- Adds the user to multiple groups.-o
- Uses the UID of an existing user.-p
- Adds an encrypted password.-s
- Sets the default shell.
How do you add or change the password of an existing account on Linux?
To add or change the password of an existing account on Linux, run:
passwd <username>
tech
group as well as the apple
and linux
groups, and whose default shell is zsh
useradd -g tech -G apple,linux -s /bin/zsh -c "James Adem" adem
What three configuration files does useradd
read from? (1)
The three configuration files that useradd
reads from are:
/etc/login.defs
./etc/useradd
./etc/default/useradd
.How do you list the default values for useradd
?
To list the default values for useradd
, run:
useradd -D
How do you change the default values for useradd
with useradd
?
To change the default values for useradd
with useradd
, run:
useradd -D <flag> <value>
What flags are available to use with
useradd -D
and what values do they change?
The flags available to use withuseradd -D
and the values they change include:
-b
or--base-dir
- The path prefix for the new home directory.-e
or--expiredate
- The date when the user account will be disabled.-f
or--inactive
- The maximum number of days after the password exceeded its maximum age where the user is expected to change their password.-g
or--gid
- The default primary group for newly created users, accepting group names or a numerical group ID.-s
or--shell
- The default login shell for new users.'
/bin/sh
and the home directory to /home/new
with useradd
useradd -D -b /home/new -s /bin/sh
Which program is used to modify an existing user on the system?
The program you use to modify an existing user on the system is usermod
.
adem
to /bin/bash
usermod -s /bin/bash adem
How do you add a user to a group?
To add a user to a group, run:
usermod -aG <group> <username>
What happens if you use just the
-G
flag withusermod
?
If you use just the-G
flag withusermod
, the user will be removed from any other supplementary group.
adem
to the sales
groupusermod -aG sales adem
Which program do you use to delete a user on the system?
The program you use to delete a user on the system is userdel
.
How do you remove a user from the system using userdel
?
To remove a user from the system using userdel
, run:
userdel <username>
How do you remove a user and their home directory using userdel
?
To remove a user and their home directory using userdel
, run:
userdel -r <username>
What should you do as a precaution when removing users?
As a precaution, before removing users you should find all the files owned by the user, assigned to a deleted user's UID, or without an owner and reassign them to any other existing user account.How do you find all of the files owned by a user by their username?
To find all of the files owned by a user by their username, run:find / -user <username>-ls
How do you find all of the files owned by a user by their UID?
To find all of the files owned by a user by their username, run:find / -uid <uid>-ls
How do you find all of the files not owned by a user?
To find all of the files not owned by a user, run:find / -nouser -ls