Permissions Troubleshooting
Review the following information to resolve permission problems in an Oracle Linux instance on Oracle Cloud Infrastructure.
Sudo to Root User Fails with "sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit" Error
After connecting to an Oracle Linux instance as the opc user and you try to switch to the root user, the following error is seen:
[opc@<oracle-linux-instance-name> ~]$ sudo su -
sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
This issue occurs if a user or process has changed the ownership and permissions on the sudo binary, and because the /usr/bin/sudo file must be owned by root, the binaries can't be run.
To fix this issue, you must reset the user and group ownership and permissions of files within the sudo package to their original values as defined in the RPM database.
Direct SSH logins as the root user are disabled by default on
Oracle Cloud Infrastructure instances for
security reasons. However, if root SSH access is explicitly enabled on the
instance, or you have set the root password and can use su to
directly access the root account, you can fix the issue directly:
If root SSH is enabled or you have the root password:
- SSH to the instance as the
rootuser, or use the su command to gainrootprivileges. - Reset the ownership:
rpm --setugids sudo - Reset the permissions:
rpm --setperms sudo - Verify the permissions:
The output shows root ownership and the setuid bit on
ls -l /usr/bin/*sudo*sudo, for example:-rwsr-xr-x. 1 root root 151424 ... /usr/bin/sudo - Exit the root session.
- Use the
sudocommand to switch to therootuser to to verify that the issue is resolved:sudo -s
If root SSH access is disabled and you don't have the root password:
Because the sudo binary is unusable, you can't run these
commands directly from the instance as the opc user. Use the
following procedure to recover access using a rescue instance:
- Using the Console, stop the affected instance. Open the navigation menu and select Compute. Under Compute, select Instances. Select the instance that you need to recover.
- Detach the boot volume from the instance. Under Storage, select the boot volume. From the menu select Copy Resource ID. Note the resource ID for use later. From the menu select Detach Boot Volume. Confirm that you want to detach the boot volume.
- Create a rescue instance with an Oracle Linux OS platform image, with the smallest available shape, in the same availability domain and compartment as the affected instance.
- Attach the detached boot volume to the rescue instance:
- In the rescue instance details, under Storage, under Attached Block Volumes, select Attach Block Volume.
- Enter volume OCID, and provide boot volume resource ID that you copied earlier.
- Select "Read/Write" access type
- Add the volume and note the device path.
- Connect to the rescue instance as the
opcuser. - Switch to root:
sudo -s - Identify the device of the attached block volume:
or
lsblkThe device matches the device path that you noted when you added the block volume.fdisk -l - Create a mount point and mount the root partition, for example:
mkdir /mnt/recovery mount /dev/sdb1 /mnt/recovery - Bind mount system directories:
for dir in /dev /proc /sys /run; do mount --bind $dir /mnt/recovery$dir; done - Chroot into the mounted file system:
chroot /mnt/recovery - Reset the ownership:
rpm --setugids sudo - Reset the permissions:
rpm --setperms sudo - Exit the chroot:
exit - Unmount the filesystems:
for dir in /dev /proc /sys /run; do umount /mnt/recovery$dir; done umount /mnt/recovery - Exit root on the rescue instance:
exit - Stop the rescue instance.
- Detach the boot volume from the rescue instance.
- Reattach the boot volume to the original instance as the boot volume.
- Start the original instance and connect as the
opcuser. - Use the
sudocommand to switch to therootuser to verify that the issue is resolved:sudo -s