Main Menu

Search

Showing posts with label sudo. Show all posts
Showing posts with label sudo. Show all posts

LINUX: How To Add User to Sudoers With NOPASSWD Without Editing /etc/sudoers File?

 
Below is the command for adding the current user you are logged in as to sudoers with nopasswd setting (not to prompt for password) without updating /etc/sudoers file.

echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/$USER

Above command adds current user to sudoers. For adding any other specific user for e.g. appuser to sudoers you can run below command as root user.

echo "appuser ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/appuser


Key Words:
 
sudo access sudoers user users password without passwd authentication authenticated prompt


LINUX: How To Enable Debug Logging In Linux For Sudo (Sudoers, Sudo Users)?

 
For Enabling Debug Logging for sudo in Linux, edit /etc/sudo.conf file and add below lines.


Debug sudo /var/log/sudo_debug.log all@debug
Debug sudoers.so /var/log/sudo_debug.log all@debug
Defaults log_input, log_output

After the debugging is enabled to sudo, you will see /var/log/sudo_debug.log file created which will have the debug information. Following is example snippet of debug log.

Mar  8 16:03:54 sudo[6337] <- sudo_new_key_val_v1 @ ./key_val.c:55 := user=olcne
Mar  8 16:03:54 sudo[6337] user_info: user=olcne
Mar  8 16:03:54 sudo[6337] sudo_getpwnam: user olcne [] -> uid 975 [] (cached)
Mar  8 16:03:54 sudo[6337] sudo_get_gidlist: looking up group-IDs for olcne
Mar  8 16:03:54 sudo[6337] sudo_get_gidlist: user olcne has supplementary gid 974
Mar  8 16:03:54 sudo[6337] /etc/sudoers.d/olcne:3: CMNDALIAS ALIAS = COMMAND
Mar  8 16:03:54 sudo[6337] /etc/sudoers.d/olcne:4: WORD(6) ALL = ( WORD(6) : ALL ) NOPASSWD ALIAS
Mar  8 16:03:54 sudo[6337] user olcne matches sudoers user olcne: true @ userpw_matches() ./match.c:498
Mar  8 16:03:54 sudo[6337] user command "/etc/olcne/scripts/olcne-image-exists container-registry.oracl
e.com/olcne/kube-scheduler:v1.29.14" matches sudoers command "/etc/olcne/scripts/": true @ command_matc
hes() ./match_command.c:672
Mar  8 16:03:54 sudo[6337] userspec matched @ /etc/sudoers.d/olcne:4:49: allowed @ sudoers_lookup_check
() ./parse.c:170
Mar  8 16:03:54 sudo[6337] keep USER=olcne: NO
Mar  8 16:03:54 sudo[6337] keep HOME=/home/olcne: NO
Mar  8 16:03:54 sudo[6337] keep LOGNAME=olcne: NO
Mar  8 16:03:54 sudo[6337] sudo_putenv:



Key Words:
 
sudo sudoing sudoers sudo user debug debugging log logging verbose verbosity access

LINUX: How To Create New Sudo User And Give Sudo Root Access To Newly Created User?

Following are steps for creating new sudo user and give sudo root access to newly created user.
1. If you want to add new sudo root user and group with same name for e.g. ss1 user and ss1 group, run below command.
useradd -d /home/ss1 -s /bin/bash -m ss1
In case you want to use different group for newly added user (with group name different than user name), Run groupadd command to create new group followed by useradd command to add new user to the newly created group.
2. Change password of newly created sudo root user as follows. In this example the user is ss1.
passwd ss1
3. Add newly created user to /etc/sudoers files. For this make below changes to /etc/sudoers file and save it.
(a) visudo
(b)  Search for below line
username ALL=(ALL) NOPASSWD: ALL
Just below above line add below line. Replace ss1 username as needed. With this we are giving sudo root access to ss1 user (without being prompted for password when running sudo command)
ss1 ALL=(ALL) NOPASSWD: ALL
4. Now login to Linux node using newly created sudo user, in this example ss1.
5. sudo to root as follows
sudo su -
You should be logged into root user without being prompted for password.

Products to which Article Applies
Oracle Linux. Steps in this Article also works on other flavors of Linux other.


Article Author: Tarun Boyella