When you try to prefix a command with sudo on a fresh CentOS system you may be greeted with a message such as “you are not part of the sudoers list” and that the incident will be reported. Not the the FBI, but to a log file. And of course your sudo operation isn’t going to work.
That’s because individual users to the system need to be granted permission to executer root level commands, even if it’s only temporary. Here’s how to do it.
In essence, you need to add your user to a file called sudoers which lives in /etc/sudoers on CentOS 6.5. This file is read only, even to the root user – so before tweaking it we need to change its permissions, otherwise your edits can’t be saved:
chmod 666 /etc/sudoers
Now use your favourite text editor and find the following section:
vi /etc/sudoers ... ## Next comes the main part: which users can run what software on ## which machines (the sudoers file can be shared between multiple ## systems). ## Syntax: ## ## user MACHINE=COMMANDS ## ## The COMMANDS section may have other options added to it. ## ## Allow root to run any commands anywhere root ALL=(ALL) ALL youruser ALL=(ALL) ALL
Add your own user name underneath the root user (as shown above), then save the file and exit. Don’t forget to change the file permissions back to 440 just like they were before:
chmod 440 /etc/sudoers