Common commands for Linux permissions

In Linux systems, permission management is a very important task. By correctly configuring the permissions of files and directories, you can ensure the security and reliability of your system. This article will introduce some commonly used Linux permission commands to help you better understand and manage permissions.

1. ls -l

ls -lThe command is used to display detailed information about files and directories, including permissions, owners, groups, etc. After executing the command, information similar to the following format will be output:

-rw-r--r-- 1 user group 4096 Aug 20 10:30 example.txt
drwxr-xr-x 2 user group 4096 Aug 20 10:30 directory

In the above example, the first column shows the permissions of the file or directory. Take -rw-r--r--for example , the first character indicates the file type, -which indicates an ordinary file and dindicates a directory. The next three characters rw-represent the owner's permissions, r--which represent the group's permissions, and the last three characters r--represent other users' permissions.

2. chmod

chmodThe command is used to modify the permissions of a file or directory. It specifies the granting or withdrawal of permissions by using different permission tags. Here are some common chmodcommand examples:

  • Add executable permissions to the file owner:

    chmod u+x file
    
  • Remove write permissions from the group to which the file belongs:

    chmod g-w file
    
  • Remove read, write, and execute permissions from other users:

    chmod o-rwx file
    

3. chown

chownThe command is used to modify the owner and group of a file or directory. You can use the following command to change the owner of the file to the specified user and the group to the specified group:

chown user:group file

For example, to example.txtchange the owner of a file to johnand the group it belongs to users, you can execute the following command:

chown john:users example.txt

4. chgrp

chgrpThe command is used to modify the group to which a file or directory belongs. You can use the following command to change the group ownership of a file to a specified group:

chgrp group file

For example, to example.txtchange the group that a file belongs to users, you can execute the following command:

chgrp users example.txt

5. umask

umaskCommand is used to set the default permission mask for newly created files or directories. Permission masks determine the permissions of newly created files or directories. Here is an example:

umask 022

The above command sets the default permission mask to 022. This means that newly created files will have permissions 644 and newly created directories will have permissions 755.

6. su

suThe command is used to switch the user identity to another user. You can use the following command to switch the current user identity to a specified username:

su username

After executing this command, you need to enter the password of the target user to successfully switch to this user.

7. sudo

sudoCommand is used to execute the specified command as a super user. Use sudoto temporarily gain administrator privileges to perform operations that require privileges, such as installing software or modifying system files.

sudo command

For example, to execute the command as superuser apt-get updateto update the package list, you can execute the following command:

sudo apt-get update

Please note that sudothe current user's password is required when using the command.

8. passwd

passwdCommand is used to change user password. You can use the following command to change the password of a specified user:

passwd username

After executing this command, you will be prompted to enter a new password and confirm it.

9. adduser

adduserCommand is used to create a new user account. Execute the following command to create usernamea new user account named:

adduser username

After executing the command, you will be asked to enter the new user's password and some other information.

10. deluser

deluserCommand is used to delete user accounts. The following command will delete usernamethe user account named :

deluser username

When executing this command, the system will ask whether to delete files and directories associated with the user at the same time.

The above are some commonly used Linux permission commands. By learning and mastering these commands, you can better manage and protect your system's files and directories.

Guess you like

Origin blog.csdn.net/weixin_43025343/article/details/132766130