How to add user into sudoers in Red Hat Linux server

How to add a user to the sudoers list?  Too many times asked this week so I have decided to write-up this simple how-to to my notes. There few different ways how you can carry out this, could be manual or by script. Manual way:

  • change to root
  • change directories to /etc
  • allow to write to sudoers file which READ-ONLY by default
  • add line with user in question and allow him to use sudo
su
cd /etc
ls -l
chmod +w sudoers
gedit sudoers
--- scroll down in file and find line (root ALL=(ALL) ALL) ---
---- right there add this for the user (example userid: roman)---
root ALL=(ALL) ALL
roman ALL=(ALL) ALL

Exit & Save
chmod -w sudoers  (make the sudoers READ-ONLY again)

All is done and now user “roman” can use elevated right with use of sudo before the command.

However if you have too many users to add, it would make sense add them to group and and add the group to sudoers instead of all separate users 🙂 [easyazon-image align=”none” asin=”1118004426″ locale=”us” height=”160″ src=”http://ecx.images-amazon.com/images/I/51V033YDe8L._SL160_.jpg” width=”127″].[easyazon-image align=”none” asin=”B006WEHNCQ” locale=”us” height=”160″ src=”http://ecx.images-amazon.com/images/I/418p4pBQ1cL._SL160_.jpg” width=”106″].[easyazon-image align=”none” asin=”0132757273″ locale=”us” height=”160″ src=”http://ecx.images-amazon.com/images/I/51a52lDdQHL._SL160_.jpg” width=”129″]

This Post Has 4 Comments

  1. Deco

    You should review this post and invert commands

    first you type chmod +w sudoers
    after editing with gedit you type chmod -w sudoers

    1. cloudman

      Thanks for correcting … fixed!

  2. tushar bapte

    i am getting following warning :

    [admin@localhost Desktop]$ sudo ./addsudoer.sh admin
    sudo: ./addsudoer.sh: command not found

    please help
    Thanks,
    Tushar Bapte

    1. cloudman

      What Linux are you running ? Did you chmod a+x addsudoers.sh ?
      Try to go to su and then execute the as a root,

Leave a Reply to Deco Cancel reply