How to block the renaming of a Particular Folder by Ubuntu Users ?
-
1You need to change the permission of the parent folder of that folder.– hunchDec 6, 2017 at 12:36
-
This question is vague. An example of the problem would provide you more useful answers. Is the renaming malicious? Is it a system folder (like /proc)? Is it a temporary directory Is it shared using NFS or Samba of FTP?– user535733Dec 6, 2017 at 13:03
1 Answer
You have to set the ownership and permissions of the parent directory (in particular the write
flag) only to the user/group which shall be able to change it.
Renaming in the end means writing to the folder which contains the file/folder.
Step 1 - ownership
sudo chown <USERNAME>:<GROUPNAME> </path/to/parent_folder>
This makes the file or folder be owned by the user
<USER>
(for blocking all normal users from the change this could be e.g.root
).The
:<GROUPNAME>
is optional and sets the group to for that file or folder.
If you don't need a special group I'ld recommend use the 's group. If you want multible users to be able to change, add them all to a new usergroup and set the ownership e.g. to
sudo chown root:<GROUPNAME> </path/to/parent_folder>
To verify it is setup as it should run
ls -la </path/to/parent_folder>
- This shows you the a list of contained files and the very first entry
.
the folder itself with information about ownership and permissions.
Output could look like
drwxrwxr-x 1 root root 0 Dec 4 16:59 .
Step 2 - permissions
followed by
sudo chmod u+w </path/to/parent_folder>
sudo chmod g+w </path/to/parent_folder>
sudo chmod o+w </path/to/parent_folder>
This makes
u+r
the owner(user) is allowed to writeg+r
the group is allowed to write (this is optional and in some cases not wanted -> than change it tog-r
)o-r
other users are not allowed to write
In some cases you might also want the -R
option for all commands to set the ownership and permissions recursively also on the content of a folder.
Note:
Anyway there is no way to prevent that root
changes anything in your system. So other users could still change using sudo
.
-
For renaming something, permissions on it don't matter. Permissions on the parent folder matter.– muruDec 6, 2017 at 13:23
-