If you are on a cloud instance you are in a bit more trouble.
There are techniques depending on distro, but if you have Docker already installed and running, then you can generally go through a Docker container to fix the problem. That is because, usually, the Docker service is running as root and anything done to a mounted volume inside the container is affected as root on the host.
docker run --rm -ti -v /etc:/usr/local/etc busybox sh
The "busybox" is just a nice small distro that won't take long to download. If you already have a Docker image that has a shell available in it, just use that.
On Docker Container:
You may have added a bad file to the
/etc/sudoers.d/ directory. In which case, probably just remove that file.
When you exit the container, you can