Friday, November 13, 2009

How to be a sudoer in Linux

Using root account is risky because it is a highly privileged account. You can accidentally delete a file, run a wrong script that will make great deal of trouble. So always try to use normal user accounts to avoid great mistakes and damages.

You can perform commands like root user using sudo from normal user accounts. For example,

# gedit /etc/grub/menu.lst 

You cannot modify that file as normal user. But this command will work.

# sudo gedit /etc/grub/menu.lst 

But you need to be a sudoer. Follow these steps to be a sudoer.
  • Login as super user (root) at this time & open a terminal. [if you don't know how press Alt + F2 and then type exactly `gnome-terminal`].

    Apply this command in the terminal.

    # gedit /etc/sudoers

  • Press down arrow key and come down until you see something like this

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

  • Now add this line after them

    YourUserName    ALL=(ALL)       ALL

  • Save the file and close the window.
Now log out and login as normal user. Add sudo before every command that you want to run as root user. You'll find it pretty easy.

Note in Ubuntu, users are sudoers by default. You need not edit any file to be that. Just apply every command preceded by sudo.

No comments:

Post a Comment