3

I want to give a non-root user the rights to view and write a specific root directory. Is this possible? If so, how?

6
  • 3
    Welcome 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? Commented Jun 9, 2020 at 16:30
  • Sorry, I'm talking about the root user libary. Not about the "/". Commented Jun 9, 2020 at 16:35
  • 1
    Does this "root user library" have a path? Commented Jun 9, 2020 at 16:59
  • What is this root user library that you talk about? Where is it? Commented Jun 9, 2020 at 17:28
  • 1
    That would probably be a bad idea. So explain why you'd want to do this. Also check: What is the XY Problem? Commented Jun 9, 2020 at 18:42

3 Answers 3

1

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
1

One simple solution is to make the non-sudo user the owner of that particular file.

chown new-owner  filename
1
  • 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. Commented May 8, 2022 at 7:45
0

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.