I have the root user, Ubuntu, […]
I don't know whether you refer to the root
user or to some regular user ubuntu
which you consider a root user for the purpose of your game. This doesn't change much in my answer though.
In Ubuntu each regular user has their own group by default. Such group by default contains only its corresponding user. This makes the following trick possible:
sudo chown ubuntu:bob fileA
sudo chmod 740 fileA
This way ubuntu
has all the permissions and bob
(as the sole member of bob
group) can only read the file.
You could do this the other way around:
# but don't! explanation below
sudo chown bob:ubuntu fileA
sudo chmod 470 fileA
but then bob
as the owner would be able to chmod
and give himself excessive permissions or to take them away from the ubuntu
group, or to mangle with "everyone else's" permissions. Any answer that advises you to make bob
the owner must consider this flaw.
You may want to set the directory ownership and permissions in a similar, yet somewhat different manner. You may want to do these changes recursively. Note that chown -R
affects directories and files, that's why you need an approach that can tell them apart. See this answer. The approach works with chmod
and chown
and other tools. Adjust it to your needs.
To recursively give directories read&execute privileges:
find /path/to/base/dir -type d -exec chmod 755 {} +
To recursively give files read privileges:
find /path/to/base/dir -type f -exec chmod 644 {} +
Can the read-only user also execute the files? – Darren – 2017-02-21T20:37:23.970