How ordinary Linux users to create files in the root administrative privileges

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/hzyyyyyyy/article/details/102557226

How ordinary Linux users to create files in the root administrative privileges

If the direct use of ordinary users to create directories directly under the root directory permissions have, the system will report "permission denied" error

drwxr--r--. 4 root     root    4096 10月 14 20:50 test
[zhangsan@node02 home]$ mkdir test/666.txt
mkdir: 无法创建目录"test/666.txt": 权限不够

When prompted ordinary users to use sudo sudo mkdir to create a file name error "User name is not sudoers file"

drwxr--r--. 4 root     root    4096 10月 14 20:50 test
[zhangsan@node02 home]$ sudo mkdir test/666.txt
[sudo] password for zhangsan: 
Sorry, try again.
[sudo] password for zhangsan: 
zhangsan 不在 sudoers 文件中。此事将被报告。

If you meet the above problems can be solved in the following ways:

-r--r-----. 1 root root 3729 10月 14 20:52 sudoers

1. Use the root user to / etc / sudoers file permissions to read:

-rwxrwxrwx. 1 root root 3729 10月 14 20:52 sudoers

Operation command: chmod 777 / etc / sudoers

2. Go to the sudoers file to be modified.
Enter sudoers file modify the command: vim / etc / sudoers
into the file / root have a place to find the root

## Allow root to run any commands anywhere 
root    ALL=(ALL)       ALL

/root   

You need to add in the bottom of the permissions the user name instead of this I use zhangsan

## Allow root to run any commands anywhere 
root    ALL=(ALL)       ALL
zhangsan        ALL=(ALL)       ALL

After writing shift +: wq save

3. Because sudoers file only become effective when the authority is -r-r -----., So after saving is complete sudoers file permissions need to be changed back to the original permissions. Modify command: chmod 440 / etc / sudoers

If you think a lot of trouble to modify sudoers file permissions can be directly input into the second step in to save modified: shift +: wq!

If you do not understand the above command 777 or 440 What is the meaning of the links below:

Linux Rights Management

Guess you like

Origin blog.csdn.net/hzyyyyyyy/article/details/102557226