1

On one of my EC2 EBS backed instances, /etc/sudoers.d/90-cloud-init-users is corrupted so I can not sudo

I tried pkexec visudo to fix it -- it asks for authentication, but won't accept credentials.

What are my options?

Wondering if there's a way to mount the volume on another instance, edit it manually, and restart?

1 Answers1

1

Yes, one way is to attach the volume to another instance to fix the problem.

  1. Shut down your instance (do not terminate!)
  2. Note down what the root volume device name is (probably /dev/sda1 or /dev/xvda)
  3. Detach the volume and attach to another "helper" instance.
  4. Fix the sudoers file.
  5. Unmount and detach the volume from the "helper" instance and re-attach to the original one using the correct name noted in step 2 above (i.e. /dev/sda1 or /dev/xvda)
  6. Start up and test.

Another way is to use AWS Systems Manager (SSM) to open an interactive session to the instance and fix it from there. Most recent AMIs come with SSM agent already installed but you may need to give the instance the appropriate IAM Role/Policy to permit access to SSM. Check out Using SSM Session Manager for interactive instance access for an intro and SSM Sessions the easy way for a helper script that makes it more convenient.

Hope that helps :)

MLu
  • 23,798
  • 5
  • 54
  • 81
  • This is what I wound up doing. The one surprise was that the actual mount point wound up being different than what I specified in the CLI command. – Kyle Banerjee May 29 '19 at 23:04