How to add a user as sudoers in Linux

Source: Internet
Author: User

Sometimes when we execute sudo

XXX is not int the sudoers file


It tells us that the current user is not sudoer, so we need to add the current user as follows:

1. Modify the/etc/sudoers file and enter the Super User. Because there is no write permission, add the write permission to chmod U + w/etc/sudoers first.

2. Edit the/etc/sudoers file and find this line: "root all = (all) All" add "zhc all = (all) all "(here zhc is your user name), and then save.

3. Finally, the system restores the write permission mode and revokes the write permission for the file. chmod U-W/etc/sudoers.


Then we can use the zhc user to edit the root file, for example

VI/etc/sysconfig/network-scripts/ifcfg-eth0

After modification, it cannot be saved directly. because we do not have the permission, we can execute

: W! Sudo tee %


This command inputs the Current Buffer content to stdin, and then the tee command imports the content from the standard input to the standard output, and then another shunt to the file. Here % represents the current file.

Original article: http://blog.csdn.net/hongchangfirst/article/details/9044591

Author: hongchangfirst

Hongchangfirst home: http://blog.csdn.net/hongchangfirst

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.