Getting a permission error when running command as root due to command not being able to access some files
Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Getting a permission error when running command as root due to command not being able to access some files
So I found the source of the problem that I posted about yesterday here. The problem is I get the following error when I run the following command with sudo (although the command runs fine without sudo):
After some further digging on my system I traced the issue to the following files in /dev. When I set the permissions of the files to 777 I have no problem running the above command as sudo, this is the ls -l output of the files as they are on a fresh boot:
Code:
crw-rw---- 1 root video 195, 255 Jan 1 04:34 /dev/nvidiactl
crw-rw---- 1 root video 195, 0 Jan 1 04:34 /dev/nvidia0
crw-rw---- 1 root video 195, 1 Jan 1 04:34 /dev/nvidia1
crw-rw---- 1 root video 195, 2 Jan 1 04:34 /dev/nvidia2
I'm hoping somebody here can shed some light on whats happening here and why the command cannot access those files. Given it's being run with sudo that should mean the command should be able to access any files it wants regardless of permissions right? The only possible situation I can imagine would be the command (when run as root and not a regular user) tries to access that file as another user, how would I find out which user this is so I can add them to the video group? The only thing I can find in /etc/passwd that might be a relevent user is the nvpd user which is already in the video group:
Code:
nvpd:x:458:27:User for nvidia-persistenced:/dev/null:/sbin/nologin
video:x:27:root,sol33t303,boinc,greetd,nvpd
How should I proceed from here? I assume anybody within the video group should be able to access the files fine, so how can I figure out who is trying to access the files so I can add them to the video group? Unless there is actually something wrong with root and root can't access those files for some reason?
EDIT:
Found the config file for the command I am running and heres it's contents, I assume I should change the "user" setting to something else but what? It seems like it should be working the way it currently is:
Have you tried adding your user to the videos group?
The command 'groups' will tell you what croups your user already belongs to.
If not already in the videos group then the command below will add your user to that group
sudo usermod -a -G videos yourusername
You will have to log out and back in for the change to take affect.
Have you tried adding your user to the videos group?
The command 'groups' will tell you what croups your user already belongs to.
If not already in the videos group then the command below will add your user to that group
sudo usermod -a -G videos yourusername
You will have to log out and back in for the change to take affect.
Thank you, I did notice that in my searches, if you have a look at my edit I said I tried that, sadly it didn't seem to do anything as far as I could tell.
And cumputersavvy I am apart of the video group, if you look in the output I posted that my username is in the video group, along with root, boinc, greetd and nvpd.
And cumputersavvy I am apart of the video group, if you look in the output I posted that my username is in the video group, along with root, boinc, greetd and nvpd.
What you posted is not the output of the groups command, but instead a line out of the /etc/group file, so it was not completely clear that your user was in that group (especially since you had not stated your username and we had no way to know your username here is the same as the username on your PC.)
If the program runs properly as your regular user, then why would you need to use sudo or run it as the root user? The linux/unix policy is to run everything with the least permissions possible so if root is not needed then you really should not use it.
In fact there are several programs (and more all the time) that check and will not run if started as root (uid=0).
What you posted is not the output of the groups command, but instead a line out of the /etc/group file, so it was not completely clear that your user was in that group (especially since you had not stated your username and we had no way to know your username here is the same as the username on your PC.)
If the program runs properly as your regular user, then why would you need to use sudo or run it as the root user? The linux/unix policy is to run everything with the least permissions possible so if root is not needed then you really should not use it.
In fact there are several programs (and more all the time) that check and will not run if started as root (uid=0).
Yeah fair enough I probably should have done it using the groups command, that would have made it clearer, I'm sorry.
The reason I need to be able use it with sudo is because LXD is root and uses the same utilities, and when LXD tries to use these utilities since it's root they don't work, I was told this by the lead LXD dev here.
Most of the time programs need to presume that, when they attempt to open a file, they may or may not succeed in doing so for any number of reasons. They need to be prepared to gracefully handle that possibility, and inform the user as required.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.