This is an introduction to “users” and “files” in Linux.
Server administrators can create users for different users and assign different privileges to ensure the normal operation of the system. They can also create users for network services and limit the privileges to reduce the damage to the system security when the services are attacked.
Modern operating systems generally distinguish between user “user” and “system user”, and divide the privileges to ensure that the integrity of the system will not be damaged by user’s misuse or malicious programs.
Users in Linux
You can see various user information in /etc/passwd
.
Root user
The root user /root
user has the highest privileges in the Linux operating system and can do anything to the system (including the extremely dangerous operation of deleting all system files). The root
user’s data is stored under /root
.
Use the root
privilege carefully to execute commands (such as sudo
), do not execute the following commands:
rm -rf /
mkfs.ext4 /dev/sda
dd if=/dev/urandom of=/dev/sda
:(){ :|: & };:
System users
System users are created by the system or related programs to perform system tasks such as services, e.g. nobody
, www-data
and so on. Do not delete these users at random.
Normal users
The normal user is located at /home/username/
and username
is the username. Normal users can log in to the system and operate on files in their home directory. They cannot directly modify the system configuration or install or uninstall software for the system environment.
Switching users
sudo
sudo
is used to execute the specified command as another user.
1 | $ sudo + command # Execute the command as the root user |
su
su
is used to switch users directly.
Note that Linux distributions such as Ubuntu disable password login for the root
user by default, so you can’t use su
directly and have to raise privileges with sudo
.
1 | $ sudo su # Switch to root |
User group
A user group is a collection of users. User groups can set permissions for a group of users. User groups also have a number GID (Group ID).
1 | $ group # See which user group you belong to |
File permissions
1 | $ ls -l # View the details of the files in the current directory |
Execute permissions
For a file, execute permission means that it can be executed as program code by the operating system. If a program file does not have execute permissions, you can still view the program file itself and modify its contents, but you cannot execute it.
For a directory, execute permission means that you can access the contents of the files in that directory. You can think of a directory as a “file”, which contains a list of files at the next level of the directory, “read” corresponds to the permission to read the list of files, “write” corresponds to the permission to modify the list of files (add, delete, rename files), and “execute” for actually accessing the files in the list, and cd
for switching from the current directory to this directory.
1 | $ chmod # change file mode bits to modify permissions |
File system hierarchy
The entire UNIX family of systems starts with /
(the root directory) as a tree; other partitions are “mounted” on this tree.
The Filesystem Hierarchy Standard (FHS) defines the standard directory structure for Linux distributions and can be found at Filesystem Hierarchy Standard. You can also use man hier
and man file-hierarchy
to see the documentation on the filesystem hierarchy on your system.
Comments