I was researching an issue recently that really threw me off, I solved the issue but I don't exactly understand why the solution works and was hoping for someone that can confirm my understanding and maybe share some insight. ChatGPT gave me an explanation that I can't find in any official documents or in the man page for sudo or on the website for sudo.
The problem: You are logged in as a user with sudo privileges and you want to copy files from a directory you don't have permissions to. The command
The solution: This was fixed by expanding the permissions of the
Final Thoughts:
ChatGPT seems to explain the situation in an obvious way, which seems valid after solving the problem, I don't know if it's inferring an explanation from the situation or giving me an actual explanation. There is no explanation of this fact in the man pages for sudo, I could not find an explanation from the community in my searches (my searches could have been bad). I even tried crawling the source code of sudo but got a bit exhausted by that. The best I can say is I confirmed that response of course by launching an actual root shell
I'm either crazy, something else entirely is going on, or it is that simple.
Is this a revelation about sudo for anyone else?
Can anyone help me identify an official explanation for this behavior with sudo?
And does anyone know other interesting or generally unexpected sudo behaviors?
The problem: You are logged in as a user with sudo privileges and you want to copy files from a directory you don't have permissions to. The command
sudo cp /var/example/files* ~/dest/
fails with the error message "cp: cannot stat '/var/example/files*': No such file or directory". The assumption was that with sudo your command (mv or cp) runs with root privileges and yet here we find, seemingly, that root could not access the source directory. The directory "example" has chmod 700 in this scenario and chown root:root, and within that directory the user actually owns the files.The solution: This was fixed by expanding the permissions of the
example
directory to chmod 777 and the best response I got from ChatGPT in trying to understand the nature of this issue was this; "sudo does not circumvent file system permissions during its own execution; it escalates privileges for the command it is executing."Final Thoughts:
ChatGPT seems to explain the situation in an obvious way, which seems valid after solving the problem, I don't know if it's inferring an explanation from the situation or giving me an actual explanation. There is no explanation of this fact in the man pages for sudo, I could not find an explanation from the community in my searches (my searches could have been bad). I even tried crawling the source code of sudo but got a bit exhausted by that. The best I can say is I confirmed that response of course by launching an actual root shell
sudo su -
and sure enough the same command above with the same original directory permissions works as expected.I'm either crazy, something else entirely is going on, or it is that simple.
Is this a revelation about sudo for anyone else?
Can anyone help me identify an official explanation for this behavior with sudo?
And does anyone know other interesting or generally unexpected sudo behaviors?