All technological notes.
root and sudoUID and GID
UID (User ID) and GID (Group ID) are both 0./root./bin/bash as the default shell, but it can be changed./etc/shadow file in encrypted form.Default Ownership
/etc/passwdsu - root
id
# uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
uid=0(root):
0, indicating the root user who has unrestricted access to the system.rootgid=0(root)
0, indicating the root group which also has full permissions across the system.rootgroups=0(root)
0, indicating the root groupcontext=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
unconfined_u (User):
unconfined_r (Role):
unconfined_t (Type):
sudo: superuser dosudo allows a permitted user to execute a command as the superuser or another user.
Feature:
/etc/sudoers file, allowing fine-grained permission control.5 minutes). This can be adjusted.| CMD | DESC |
|---|---|
sudo -l |
List available commands. |
sudo command |
Run command as root. |
sudo -u user command |
Run as user. |
sudo -s |
Start a shell |
sudo -u user -s |
Start a shell as user |
sudo, the current user must be in the sudoers file.These users can then precede one of those commands with a utility called sudo (superuser do, a.k.a. substitute user do) at the time of executing that command. The users are prompted to enter their own password, and if correct, the command is executed successfully for them.
visudo
sudo file.Example: Enable a user to execute a previlige command
/etc/sudoers File
visudo command, which prevents syntax errors that could lock you out.user host=(users) [NOPASSWD:]commands
full access
# full access to every administrative function
root ALL=(ALL) ALL # root
user1 ALL=(ALL) ALL # user
%dba ALL=(ALL) ALL # group
user1 ALL=/usr/bin/cat
%dba ALL=/usr/bin/cat
# No password prompt for all
user1 ALL=(ALL) NOPASSWD:ALL
%dba ALL=(ALL) NOPASSWD:ALL
# No password prompt for a command
john ALL=(ALL) NOPASSWD: /bin/systemctl restart apache2
Cmnd_Alias PKGCMD = /usr/bin/yum, /usr/bin/rpm
User_Alias PKGADM = user1, user100, user200
PKGADM ALL = PKGCMD
su -
# create a new usesr
useradd devops
passwd devops
# edit the /etc/sudoers file
sudo visudo
# devops ALL=(ALL) NOPASSWD: /bin/yum
# Test
# switch user
su - devops
sudo yum upgrade -y
# try other commands
sudo cat /
# Sorry, user devops is not allowed to execute '/bin/cat /' as root on rhelhost.localdomain.
The sudo command logs successful authentication and command data to the /var/log/secure file under the name of the actual user executing the command
tail /var/log/secure
# Feb 15 19:42:23 ServerB groupadd[4391]: new group: name=dba, GID=5000
# Feb 15 19:43:20 ServerB usermod[4398]: add 'user100' to group 'dba'
# Feb 15 19:43:20 ServerB usermod[4398]: add 'user100' to shadow group 'dba'
# Feb 15 19:46:35 ServerB groupmod[4411]: group changed in /etc/group (group linuxadmin/5000, new name: sysadm)
# Feb 15 19:46:35 ServerB groupmod[4411]: group changed in /etc/gshadow (group linuxadmin, new name: sysadm)
# Feb 15 19:46:53 ServerB groupmod[4425]: group changed in /etc/group (group sysadm/5000, new gid: 6000)
# Feb 15 19:46:53 ServerB groupmod[4425]: group changed in /etc/passwd (group sysadm/5000, new gid: 6000)
# Feb 15 19:48:36 ServerB groupdel[4432]: group 'sysadm' removed from /etc/group
# Feb 15 19:48:36 ServerB groupdel[4432]: group 'sysadm' removed from /etc/gshadow
# Feb 15 19:48:36 ServerB groupdel[4432]: group 'sysadm' removed
wheel Groupwheel group
wheel group are allowed to execute commands as the root user or another privileged user via the sudo command.wheel group gives users permission to execute sudo commands, effectively allowing them to perform administrative tasks.wheel group to control who can perform privileged actions./etc/group
wheel:x:10:rheladmin,testuser/etc/sudoers
%wheel ALL=(ALL) ALL# Create the New User
sudo useradd devops1
# Set a Password for the User
sudo passwd devops1
# Add the User to the wheel Group
sudo usermod -aG wheel devops1
# Verify
groups devops1
# devops1 : devops1 wheel
# Test the Configuration
# Switch to the devops1 user:
su - devops1
# test sudo command
sudo yum update