TL; DR
Log in with the same user with whom you did all the actions described.
Run the umask
command to find out the default permissions of your user. The command will return you a number in octal base, type 0002
(ignore the first 0
, because, like 0x
that precedes every number in hexadecimal base, the first 0
is irrelevant. p>
If the files you have modified do not are directories, then subtract the value obtained with the umask
command from 666
, and use the resulting value in a new chmod
command to be files. Example:
$ umask
Resultado: "0002"
666 - 002 = 664
$ chmod 664 NOME_DO_ARQUIVO
But if the modified files are directories, replace 666
in the above calculations with 777
.
Explanation of what happened there
Permissions on a Unix / Linux system are defined by the following sequence of characters:
_rwxrwxrwx 1 dono:grupo
_
at the beginning you can ignore your problem (it's a special permissions flag, and you can sort the file with special permissions from file , directory , or < strong> no special permissions )
Then there are 3 sets of rwx
(where r
represents read permission, w
write permission, and x
execution). The first set displays the permissions of the user who owns the file (who created the file), the second set is the permissions of the group to which the file belongs (a group can contain more than one user), and the last set of permissions are the permissions for all other system users.
dono:grupo
represents which user and group the file belongs to.
Then a file with the following _rw_rw_r_
permissions can be Read and Written by the owner of the file and by the users belonging to the file group. Other users can just read the file.
To change the permissions of a file you use the command chmod
followed by 3 numbers representing, in order, the permissions for Owner, Group, Other Users. The numbers can be:
- 4 for Reading
- 2 for Writing
- 1 for Execution
- any sum of the above (e.g. 4 + 2 = 6, represents Read + Write permission)
That's why your chmod 777
command freed everything you wanted to do in the file, because 7 = 6 + 2 + 1, ie Read, Write, and Execute permission to the owner, group, and other system users. p>
So now you know how to set permission for files or directories the way you want, but what about
Now I would like to return to the default Linux system files.
For this you can use the command umask
. It returns which non permissions should be set on all files and directories created by the current user on the system. For standard (non-root) users, the default value is 0002
(ignore the first 0
that only indicates that the number is in octal base), while for root users the default is 0022
.
Then to set the permissions of a normal file, subtract the value returned by umask
from 666
and use that new value in the chmod
command.
And to define directory permissions, subtract the umask
from 777
.
References
link
link