Add User To Sudoers Centos RHEL 7

Add User To Sudoers Centos RHEL 7:

All users doesn't have permissions like root user, root user has the all permissions to install any packages or download any packages. To install or to download any packages or to do any activities in the centos/rhel/debian/ubuntu we need more permissions as like root user. In the following example i will show you how to add user to sudoers in centos or rhel or how to get permissions as like root user or make user as a sudo user in centos/rhel. Sudo user is nothing but is having permissions like root user. So the sudo user can download any packages and the sudo can install any packages.

Ex:

I have user called devops now i am trying to install httpd.

[devops@localhost ~]$ yum install httpd
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
You need to be root to perform this command.
[devops@localhost root]$ 

But when i tried to install httpd it is showing that you need to be root to perform this command.

That means the user devops has no permissions to install any packages. For that we need to make devops user as sudo user.

[devops@localhost ~]$ sudo yum install httpd

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for devops: 
devops is not in the sudoers file.  This incident will be reported.

You can see that it is asking password of devops user. I entered password of devops user, But still the task is failed since the user devops is not the sudo user. For that we need to make devops user as sudo user. By giving sudo access to any user, user can download packages and the user can install that packages as like root user.

Adding User To Sudoers in Centos RHEL 7:

To give users to sudo permsiions we need to add that users to /etc/sudoers file.

To add any user to /etc/sudoers file we need permsions, We cant add directlry to /etc/sudoers file. Only root user can add users to /etc/sudoers file, So for that first logout from devops user and login as root user. After login as root user add below line in /etc/sudoers file.

as a root user  vi /etc/sudoers

syntax is:

<username>       ALL=(ALL)       ALL

devops  ALL=(ALL)       ALL

Enter above line in /etc/sudoers file and save it. And now login as a devops user and try to install any package

Executing commands with sudo access:

[devops@localhost ~]$ sudo yum install httpd
[sudo] password for devops: 
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
              : manager
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-88.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package      Arch          Version             Repository                 Size
================================================================================
Installing:
 httpd        x86_64        2.4.6-88.el7        rhel-7-server-rpms        1.2 M

Transaction Summary
================================================================================
Install  1 Package

Total download size: 1.2 M
Installed size: 3.7 M
Is this ok [y/d/N]:

You can see here, after entering install command with sudo, It will ask password of devops user. So we need to enter password of devops user. Now the httpd will install and we got full permissions as root user.So successfully we have added user to sudoers in centos/rhel.

 

 

  • Add User To Sudoers Centos
  • Add User To Sudoers rhel 7
  • sudo user centos
  • sudo user rhel 7
  • create sudo user in centos
  • create sudo user in rhel 7
  • add users to sudoers file

Leave a Reply

Your email address will not be published. Required fields are marked *