Sudo stopped working on Synology NAS
Quick and dirty way to make sudo work again with your admin account.
November 2, 2023
I'm using my home Synology NAS to run Docker containers with various services and APIs that I use locally in my network. One of my containers is hosted on the GitHub Container Registry, which is not supported in the NAS GUI, so I had to use SSH to authenticate to this registry and download Docker images manually.
Except for the annoying fact that every
sudo required me to re-enter my admin password, this worked fine. Until it didn't. One day I started getting: Sorry, try again. when running any sudo command and entering the right password. Google didn't help much, but it inspired me to get to the solution that I finally used.
There's a trick that allows running any script as root on the NAS, using Task Scheduler:
Control Panel -> Task Scheduler -> Create -> Scheduled Task -> User-defined script -> Uncheck Enabled -> Task Settings -> Fill User-defined script -> OK -> Run.
I used this method to copy the
sudoers file to a shared folder ("systemshare"):
cp /etc/sudoers /volume1/systemshare/sudoers
Then I downloaded the file and added just one line:
# ... original sudoers content ... # myownadminuser ALL=(ALL) NOPASSWD: ALL
(In reality, "myownadminuser" is the actual username of my main admin account.)
And copied it back, using another "scheduled" task:
cp /volume1/systemshare/sudoers /etc/sudoers
This removed the annoyance of having to re-enter the password every time I wanted to do privileged operations with my administrator account, and also allowed me to sudo again.
Does this survive the next Synology update? I don't know yet... There's always a risk with these things that some automated proces will restore system files to their original/desired state. We'll see.
Found something inaccurate or plain wrong? Was this content helpful to you? Let me know!