I want to give a non-root user the rights to view and write a specific root directory. Is this possible? If so, how?
-
3Welcome to Stack Exchange! We probably need some additional information to help you out. What exactly do you mean by "a specific root directory"? Are you talking about "/" or a directory owned by user "root"? What do you want to accomplish?Martin Konrad– Martin Konrad2020-06-09 16:30:41 +00:00Commented Jun 9, 2020 at 16:30
-
Sorry, I'm talking about the root user libary. Not about the "/".MuteBefehl– MuteBefehl2020-06-09 16:35:36 +00:00Commented Jun 9, 2020 at 16:35
-
1Does this "root user library" have a path?Eduardo Trápani– Eduardo Trápani2020-06-09 16:59:49 +00:00Commented Jun 9, 2020 at 16:59
-
What is this root user library that you talk about? Where is it?ctrl-alt-delor– ctrl-alt-delor2020-06-09 17:28:34 +00:00Commented Jun 9, 2020 at 17:28
-
1That would probably be a bad idea. So explain why you'd want to do this. Also check: What is the XY Problem?A.B– A.B2020-06-09 18:42:30 +00:00Commented Jun 9, 2020 at 18:42
3 Answers
The direct answer to your question is certainly not the best solution. You'll want to put the files you want to share into somewhere a little more public. To let everyone see it (but only the owner writes to it):
# mkdir -p /path/to/share/
# mv /root/sharedfile /path/to/share/
# chmod 644 /path/to/share/sharedfile
If you really want to give a non-root user access to /root consider adding them to group sudo or adding them to /etc/sudoers. Then they can access /root by doing something like:
$ sudo ls /root
One simple solution is to make the non-sudo user the owner of that particular file.
chown new-owner filename
-
The question concerns a directory (possibly even one of the top-level directories), and depending on what directory this is, giving a non-root user ownership of it could break the system or provide a security hole.2022-05-08 07:45:13 +00:00Commented May 8, 2022 at 7:45
Yes, assuming you have root privileges, it is possible. root can do anything (except on newer Macs) - even if it's not ordinarily a good idea.
One way to do this is to use your root privileges to simply add your non-root user (call him nonroot for this answer) to the sudoers file:
sudo visudo
Once the sudoers file is open, you can add the following:
nonroot ALL = (ALL) ALL
Save & close the sudoers file, and it is done.
Note this gives user nonroot the same privileges as root.... and root can do anything.
But I may have misunderstood your question... If your question was how to allow nonroot to access files or folders under /root (e.g. /root/librarydir), the answer is a little different. Instead of the line above, add this line instead:
nonroot ALL = (root) sudoedit /root/librarydir/*
This gives user nonroot the ability to make changes to files in that location.