In my experiment, I change /etc/passwd like following.
Now the root user id be 1234, and I guess that is the reason which make all sudo
command not effect.
I can not restore the /etc/passwd
, because of lack writing permission.
Is there any solution ?
root:x:1234:1234:root:/root:/bin/bash
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
PS. This enviroment is WSL2 archlinux. But I try using notepad with administrator permission, still cannot change the file. If there is a suitable method, please also let me know. Thanks.
Finally I solve it.
# export the distribution:
wsl --export <Distribution Name> <FileName>
# change the passwd file in the rar: /etc/passwd
# delete old distribution
wsl --unregister <Distribution Name>
# reimport the fixed distribution
wsl --import <Distribution Name> <InstallLocation> <FileName>