I need to restore /etc/shadow with the contents of /etc/shadow.bak. I don't have a sudo password but was told that maybe "Non-default shadow group permissions" would help?

I run

sudo -ll

I get the following

james@machine:~$ sudo -ll
Matching Defaults entries for elf on 8ee2351512ca:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User james may run the following commands on machine:
Sudoers entry:
    RunAsUsers: james
    RunAsGroups: shadow
    Options: !authenticate

Permissions on shadow are as follows

james@machine:~$ ls -laah /etc/shadow
-rw-rw---- 1 root shadow 0 Dec 15 20:00 /etc/shadow
  • 2
    After you have received an answer, you can no longer delete your post so others can use this Q&A pair if they have a similar problem. – Sven Dec 16 '17 at 20:51

You can run /usr/bin/find as group shadow and group shadow has write access to /etc/shadow so you may be able to do something like this

sudo -g shadow find /path/to/shadow.bak -exec cp {} /etc/shadow \;

This should work as the exec is run with the user:group of the calling process which in this case would be james:shadow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.