-3

I have very limited knowledge in all things Linux so if somebody could just tell me the commands I need to run to finish up this project I've been beating my head against.

I have a folder called /data, I have these 4 users admin, nwadmin, hwadmin, and ro and I need the user ro to have read-only access to that /data folder and all subfolders, while the other 3 users have full access. What commands do I need to run to accomplish this, please? Thanks in advance!

I'm using Ubuntu Server 14.04 LTS, I haven't tried anything yet as I'm scared to do so. I know it probably uses chown and chmod but I don't understand those commands at all, no matter how many times I read how to do it.

Melebius
  • 11,431
  • 9
  • 52
  • 78
  • Which version of Ubuntu are you using? Is it a desktop or a server? What have you tried? What errors do you get? Please edit your question above and add all the details of your problem. – user68186 Mar 12 '19 at 13:57
  • Sorry I have added more info, and yes Melibius I guess it would be fine to make it read only for all then a group for the 3 admins and owned by the admin group. What commands would I run to do this in order please and thanks! – DarkOneX Mar 12 '19 at 15:06

1 Answers1

-1

If I understand correctly, you want to set read+write permissions for a group of users and grant read-only access to everyone else. This can be done using the command line.

Disclaimer & further reading

Before running any of the commands from the internet, you should understand what they do. The simplest way is to read their manual pages.

Procedure

  1. Add (+) the group write and read permission for the folder Recursively. Add the read permission and remove (-) the write permission for others.

    chmod -R g+rw,o+r-w /data
    

    Don’t change the permissions using number codes as especially the execute permission may vary among files and folders and should be kept.

  2. Create a new group, e.g. admins, and add all the users who shall get read+write permissions to it.

    sudo addgroup admins
    for user in admin nwadmin hwadmin; do sudo adduser $user admins; done
    #              ↖    ↑    ↗
    #   list the users here
    
  3. Set the folder as owned by the admins group (Recursively).

    chgrp admins /data
    

Additional notes

As you have claimed to “have very limited knowledge in all things Linux”, I’d like to bring your attention to the following concerns.

Using sudo

You can find a lot of sudo chmod commands on the internet. sudo should be only used for system-wide administrative tasks (like adding a new user group to the system above) but not to modify a user’s folder. Make sure to run the chmod and chgrp commands as the owner of the folder.

Paths

I have a folder called /data

Paths beginning with a / are absolute paths on Linux. If your folder does not reside in the root (/) folder, make sure to put the right path in the above commands. The best way is to have the working directory set to the superfolder of data (e.g. if the folder is /home/shared/data, issue the command cd /home/shared) and then use data (without the leading /) as the path argument.

Melebius
  • 11,431
  • 9
  • 52
  • 78