Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm a beginner. I'm trying to give my user root permissions, so I edited the sudoers file like this:

black   ALL=(ALL)   ALL

"black" is my username.

But I still don't have root permissions, and when I open the terminal, it shows me:

[black@Black ~]$

Another thing. In the Administration > Users and Groups, my user's primary group is root.

My Linux is the latest version of CentOS.

share|improve this question

3 Answers 3

Now that you have your sudoers file set up, to execute commands with root permission use sudo.

$ sudo cat /etc/shadow
share|improve this answer
    
Do you mean before any command i should type sudo? Is there any other way? –  Siamak A.Motlagh Sep 10 '12 at 18:27
3  
@Siamak.A.M : The idea of sudo is that you work at the lowest privilege level and elevate to a higher privilege only when you specifically need it. Yes, this leads to learning to type 'sudo' before a command. You can better understand this too, when you realize that sudo logs the commands you enter for auditing and accountability. –  JRFerguson Sep 10 '12 at 18:35
    
@JRFerguson Thanks for your answers. just one question. i installed php aphache and mysql. I wanna move a file, for example index.php to "var/www/html/" but it says: Error moving file: permission denied! how can i fix this problem ? –  Siamak A.Motlagh Sep 10 '12 at 18:50
    
@Siamak.A.M you are asking new questions and as such they deserve a new thread. –  JRFerguson Sep 10 '12 at 18:54
1  
@JRFerguson It's not intended for you to give a user root access 100% of the time. You are only supposed to use it for individual commands only if that command requires it. Use sudo cp index.php /var/www/html not just cp alone. This is The Way, and it is better. –  bahamat Sep 10 '12 at 21:27

Now that you've given your account sudo access, you can:

  1. Run commands that need root privs with sudo command. Note that if you need to redirect output from command, the redirection is happening in the context of your current shell so will have your user's privileges not root's (I mention this because it tends to surprise people)

    Every command you run with sudo like this is logged, which is useful as an audit trail of what you did and when. It's also useful on shared systems when multiple people have root access via sudo.

  2. Write a script to do what you need and run it as sudo scriptname as above. The entire script will be running as root, so redirection etc will work as expected with root privs.

  3. Run sudo -i to give yourself a root login shell (i.e. with the environment set up as if you had logged in as root), run any commands you need while in that shell, and then type exit to return to your non-root shell.

    Only the fact that you started a shell with sudo will be logged, not the individual commands in that shell (although they will still be saved in root's history).

share|improve this answer

If you do not want to type sudo before every command you can type first:

sudo -s

It will ask you to enter password of your user and then you will be put to shell as root user until you will exit from that shell. I am not sure if it will work on CentOS as I do not have access to one, but it is working on Debian. You can try if it will be working for you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.