How to Provide Sudo Privilege to Oracle User or any other OS user? (Or in otherwords, how to include any OS user in Sudoers List?)

BaskarBaskar
3 min read

In this article, I will guide you on how to add Oracle OS User or any other OS user to Sudoers list? In otherwords, I will guide you on how to provide Sudo privilege for an OS user?

Identify whether the User has Sudo Privilege or not?

First identify whether the User is already having the Sudo Privilege or not by executing the following command as “root” user.

$ sudo -l -U oracle

As you see from above output, here the User “oracle” is not having the Sudo Privilege. Here, in the output, the word “bbabu” refers to the Hostname. i.e. My server / hostname is bbabu. So, don’t get confused that the ‘bbabu’ is also an another User.

Method 1:

In the method 1, execute the following command as “root” user which will open the “Sudoers” file.

$ sudo visudo

Then, after opening the file, you will see a line for the “root” user similar to the one as shown below.

Once you identified that line, just add one more line with the OS user that you wanted to have the sudo privilege. Here, I am going to add “oracle” user and then save the file.

Once it is done, you can start running the command with sudo privilege for the “oracle” user. For example, I am now logged in as “oracle” user and then I am trying to change the permission of a file which is owned by “root” user. But, then, I am going to execute the same command with “sudo” privilege. And, you can see that the command will be executed successfully.

Method 2:

In the method 2, You will be creating a separate sudo file for the OS user that you wanted to have the “sudo” privilege. This file should be created under the “/etc/sudoers.d” directory as shown below.

Login as “root” user and create the file for the “oracle” OS user.

$ cd /etc/sudoers.d
$ pwd
$ touch /etc/sudoers.d/oracle-sudo

As you see above, I created an empty file called “oracle-sudo”. Basically, the syntax/best practice for the filename will be like “username-sudo”

Then, open the file in your favorite editor, and add the following line in this file and save it.

oracle ALL = (ALL) NOPASSWD:ALL

Then, restart the server to take effect. (Note: In my scenario, the sudo privilege took effect only after I restarted the server whereas the Method 1 didn’t require any server restart).

Finally, let me show you the first command once again wherein you can confirm / observe that this time the “oracle” OS user has got the “sudo” privilege.

Thanks for reading this article. Hope, this helped you to progress your work!.

0
Subscribe to my newsletter

Read articles from Baskar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Baskar
Baskar