The system is Ubuntu20.04, use VsCode to log in to the host in the local area network ssh.
In order to provide write permission for vscode that ssh logs in to the host, try to use this command to give vscode read permission for the entire etc folder
sudo chown -R $USER /etc
Then there is no way to use sudo
There is only one user, no super administrator, no sudo and no way to modify the permission configuration file.
When trying to change the permissions back to all users, I can't continue because I don't have sudo. . . Into an endless loop
chown -R root /etc
But referring to this operation, it can replace the direct sudo command of the current user
https://iqcode.com/code/shell/sudo-etcsudoers-is-owned-by-uid-1000-should-be-0
The specific operation is to create two remote connected terminals, let’s call them Terminal 1 and Terminal 2:
In Terminal 1 type:
echo $$
Note down the process number
Then inside Terminal 2:
pkttyagent --process <上一步看到的号码>
It will get stuck after running, this is normal
Go back to Terminal 1 and re-enter the command to use with pkexec instead of sudo:
pkexec chown -R root /etc
At this time, Terminal 2 will prompt you to enter the password
Enter the password and return to terminal 1. In fact, the command of terminal 1 has been successfully run with root authority at this time.
sudo works again
The reason why sudo fails to use such troublesome means is often because there is no super user set up. It is recommended to complete the initialization of the super user as soon as possible after this
sudo passwd root
In this way, when encountering such problems, you can enter the super user to deal with them.