Good people! ๐ First of all, it is worth mentioning that it is my first contribution to the community, I hope someone will find it useful
=> Basic structure of permissions in files
=> Basic structure of permissions in directories
=> User, Groups and Others
=> Chmod octal
1.- Basic structure of permissions in files
There are 3 basic attributes for simple files: read, write, and execute.
>> Read permission (read)
If you have permission to read a file, you can see its content.
>> Write permission (write)
If you have permission to write a file, you can modify the file. You can add, overwrite or delete its content.
>> Execute permission (execute)
If the file has execute permission, then you can tell the operating system to run it as if it were a program. If it is a program called "foo" we can execute it as any command.
Or a script (interpreter) that needs read and execute permission, a compiled program only needs to be read.
The characters attributed to the permissions are:
r means writing and comes from Read
w means reading and comes from Write
x means execution and comes from eXcut
Using chmod to change permissions
chmod (change mode) is the command used to change permissions, you can add or remove permissions to one or more files with + (plus) or - (minus)
If you want to prevent yourself from modifying an important file, simply remove the write permission on your "file" with the chmod command
$ chmod -w yourFile
if you want to make an executable script, write
$ chmod + x tuScript
if you want to remove or add all attributes at once
$ chmod -rwx file $ chmod + rwx file
you can also use the = sign (equal) to set the permissions in an exact combination, this command removes the write and execute permissions leaving only the read one
$ chmod = r file
2.- Basic structure of permissions in directories
In the case of directories we have the same permissions, but with a different meaning.
>> Read permission on a directory
If a directory has read permission, you can see the files it contains. You can use an "ls (list directory)" to see its content, just because you have read permission on a directory does not mean that you can read the content of its files if you don't have read permission on those.
>> Write permission on a directory.
With write permission you can add, remove or move files to the directory
>> Execute permission on a directory.
Execution allows you to use the name of the directory when you are accessing files in that directory, that is, this permission makes it take into account in searches carried out by a program, for example, a directory without execution permission would not be checked by the command find
3.- Users, Groups and Others
Now we know the 3 permissions and how to add or remove them, but these 3 permissions are stored in 3 different places called.
User (u) comes from user
Group (g) comes from group
Others (or) comes from other
When you run
$ chmod = r file
Change the permissions in 3 places, when you list directories with "ls -l" you will see something similar to.
-r - r - r-- 1 wada users 4096 Apr 13 19:30 file
note those 3 r's for the 3 different types of permits
where:
x ------------- x ------------- x | permissions | belongs | x ------------- x ------------- x | rwx ------ | user | | --- rx --- | group | | ------ rx | other | x ------------- x ------------- x
we can remove permits for each owner; suppose we have a file:
-rwxr-xr-x 1 wada users 4096 Apr 13 19:30 file
To remove the execution permissions to groups and others, just use:
$ chmod gx, ox file
our file will have these permissions
-rwxr - r-- 1 wada users 4096 Apr 13 19:30 file
if you want to remove user write permission:
$ chmod ux file
-r-xr - r-- 1 wada users 4096 Apr 13 19:30 file
Adding and removing two permissions at the same time:
$ chmod u-x + w file
-rw-r - r-- 1 wada users 4096 Apr 13 19:30 file
Very simple right?
4.- chmod in octal
The octal representation of chmod is very simple
Reading has the value of 4
Writing Instruments has the value of 2
Execution has the value of 1
Then:
x ----- x ----- x ----------------------------------- x | rwx | 7 | Read, write and execute | | rw- | 6 | Reading, writing | | rx | 5 | Reading and execution | | r-- | 4 | Reading | | -wx | 3 | Writing and execution | | -w- | 2 | Writing | | --x | 1 | Execution | | --- | 0 | No permissions | x ----- x ----- x ----------------------------------- x
Thus:
x ------------------------ x ----------- x | chmod u = rwx, g = rwx, o = rx | chmod 775 | | chmod u = rwx, g = rx, o = | chmod 760 | | chmod u = rw, g = r, o = r | chmod 644 | | chmod u = rw, g = r, o = | chmod 640 | | chmod u = rw, go = | chmod 600 | | chmod u = rwx, go = | chmod 700 | x ------------------------ x ----------- x
I never made sense of the octals ๐ Thanks for the article!
a simple trick is to see it in binary: rwx represent 3 bits (Read, Write, eXecute). If you want read and write permissions, you would have 110 binary, which in octal is the number 4. Also if you know that it is organized as GUO (Group, User, Others) you have already done it. Example: read, write and execute for group and user; reading and performance for others; would remain: 111,111,101 -> 775
Thank you. I had not seen that way
Be careful because 110 binary is not the number 4 in octal.
The binary number 110 is octal the number 6
Basically we have on the one hand the user or users and on the other hand the permissions
Permissions:
r = read (read)
w = write
x = exe (execution)
- = no permission.
Users:
u = owner, administrator.
g = group.
o = all others.
With ls -l we see the permissions either directory or file to give them all for example with:
sudo ugo + rwx 'filename' // We would give all permissions.
it goes straight to the notes
.
thanks!
Very good!
Very good.
Good!
Very good article, but a little correction should be made:
r means writing and comes from Read
w means read and comes from Write
x means execution and comes from eXecute
(R) Read is Read and (W) Write is Write
A greeting!
That happens for making notes late at night hahahaha sorry for my mistake as soon as I can correct it, right now I get a mistake, Thank you ๐
It gives you an error .. ..because no matter how much you are the author of the post, you are not given permission to edit it once it is posted ..
Another small mistake .. ..in point 3 .- .. when you say "if you want to remove the write permission from the user" .. you put "$ chmod ux file" .. ..and it should be "$ chmod uw file" ..to match what you say .. and the result ..
Annotated
r means READ and comes from Read
w stands for WRITE and comes from Write
x means execution and comes from eXecute
I have tried to share a folder with Samba, and give read and write permissions to guests, but the case is that when I create a new folder from one of the two computers (guest or client) that new folder does not have read and write permissions assigned write for everyone ... Is there a way to fix that without having to edit the permissions every time a folder is created? It's a bit cumbersome. By the way, I do everything through a graphical interface.
Inquire about setfacl
Very clear article. A detail, where it says:
| chmod u = rwx, g = rx, o = | chmod 760 |
Should be:
| chmod u = rwx, g = rw, o = | chmod 760 |
O well:
| chmod u = rwx, g = rx, o = | chmod 750 |
Why friend?
Because x is equal to 5 and in the example it is as 6
g = rx 6 Error
g = rx 5 Correct
g = rw 6 Correct
For Dark Purple:
From what little I am still learning, I have rescued this knowledge (which I don't really know if it will help you in your problem, but it is worth trying; and it is missing in this publication):
Give recurring permissions (-R) like this:
chmod -R 777 parent_directory / *
This would give all the permissions to all the users, groups, and others regarding the parent folder, and to all the folders and files that are inside (permissions by default for the new ones created in this directory, at least that's the way it is in my slax)
Graphically, you should look for an option that says "make this command recurring" or "do this for included folders"
I am one of those who always threw the 777 to my machine for convenience, but with these commands I am going to put the batteries and be more cautious, thanks for the contribution!
Thank you, you got me out of doubt
Very good contribution ... keep it up ...
very very good thank you ๐
Excellent explanation, finally it is clear to me of one ...
Hello there!
Look, I do not know if it is relevant but I have a problem with the permissions to record, delete, in my mp4. It won't let me change the permissions, so it's only read. Enter the commands you gave but the answer was
chmod: changing the permissions of "/ media / 0C87-B6D2": Read-only file system
I have reviewed many forums and nothing has worked for me, I tell you that I am a beginner in this so it may be that something I am doing wrong.
I hope you can help me.
kisses
Try logging in as super user
You may not have the proper driver. With the NTFS filesystem it won't let you write unless you have the ntfs-3g package installed. I do not know the mp4 what system it will have ...
Excellent, thank you.
thanks for tutorial ๐ very useful
coincidentally I was reading about the chmod command in a guide on linux systems administration, which was also clear to me, only that there they told me about 3 more commands -s -S and -t which are additional permissions, that was what I did not I am clear, tomorrow I will read another good read, very good your tables, greetings
The contribution is appreciated. Just what I needed
Hello, very interesting, I would like to know how or as well with what program I can edit files, chmod or what are in that folder,
I want to edit some permissions, which are there ...
Or how is this ... thank you
Thank you
Very well explained, thanks
EXCELLENT CONTRIBUTION, THANK YOU FOR GIVING PART OF YOUR TIME TO DO IT.
Good contribution. Thanks for the. I would like to make a clarification that I consider important. In Spanish remove is not equivalent to English remove. In Spanish remove does not mean to eliminate.
According to the RAE it means:
1. tr. Passing or moving something from one place to another. U. tc prnl.
2. tr. Moving something, shaking it or spinning it, usually so that its different elements mix.
In this sense, instead of removing, the verb remove should be used.
It's true, I say Remove myself when I remove something, especially in computer terms.
Missing you add the third line ...
3. tr. Remove, set aside, or obviate an issue.
I never said it in an effort to "Eliminate" if not to remove ๐ sorry if it was meant to eliminate. Thanks for stopping by and for the clarification I will take it into account.
Good
Please someone clarify a question, that as I understand it applies only to the user and the group that owns the file or directory, but if I have a user or group "xyz" for example, how do I assign permission either from r, or wx only to that user or group and not to the owner (s).
How can I see the permissions of a specific group and how can I edit them so that it has the same root permissions
Hello, I have a little problem, I have a pc in lubuntu and in the domain with the local user, it does not give a problem but with the domain user, and it is at the time of opening mozilla and the thunderbird that the whole system is frozen I hope they can help me
cheers
Excellent explanation
Excellent articleโฆ I would only like to be able to count on the answer of some pious person from this forum, regarding the following question: ยซIf I add a user A to my GROUP group, whose permissions of this GROUP group are rwx, all the users of this group , including A, will these rwx permissions on the internal files / directory? Taking into account that the internal files already have rwx for the GROUP group? Thank you!!!!!! ๐
Good job. Simple and understandable.
I am absolutely new to this and this info. It worked out wonderfully for me. Thank you.
Excellent contribution, very useful, thank you (:
Very instructiveโฆ Very pedagogical.
Thanks for the article, it helped me a lot, this is very confusing xDDDD
Your contribution is very useful, strangely I have a problem that the files that I have always used are "read only" execute
chmod 777 file
root @ Leps: / home / leps # chmod: changing the permissions of "Downloads / canaima-popular-4.1 ~ stable_i386 / canaima-popular-4.1 ~ stable_i386.iso": Read-only filesystem
and with all the files it is the same, in fact I ran it with Ctrl + Alt + F1 as root and it is the same. What I can do?
Excellent information!! It was very helpful to me.
Thank you very much.
Very good note. I was urged to apply permissions and thanks to this tutorial, I was able to do it in minutes. Highly recommended
I did a chmod -R 777 on the root of my installation, that is /
and restart the kali linux and now it does not load
Any idea?
Yes, everything broke, you have to reinstall Ubuntu, and I know because the same thing happened to me !!!
The tutorial is very good, very complete. Maybe small errors, but it has already been commented that they cannot be edited. Still very good to learn
r means writing and comes from Read
w means read and comes from Write
There you got confused. r read read, w modify write
Very useful! For those of us who are not very into Linux administration, these tutorials are great.
Congratulations on the blog!
Greetings visitors of Desdelinux Blog.
A funny thing happens to me using an ubunter distro like LMint.
I copy and paste a theme folder to the / usr / share / themes directory by using 'sudo' (asking for my user's password).
There in that system folder, when making a list using 'ls -l', or 'ls -la', said theme folder or theme, is owned by my username (and group), that is, not by Root.
So, I am about to make the change to remove the write permission from my user on said directory of the downloaded theme, since when reviewing all its files and folders recursively with 'ls -laR', my user is the only one who can write to said folders and files. Sure I guess almighty Root too.
Positioning myself from Terminal, with 'cd / usr / share / themes / the-theme-downloaded', and then simply executing 'chmod -Rv uw *', without requiring 'sudo' or root permissions. He informed me that he successfully modified my user's write permission to all files and subfolders of 'the-theme-downloaded'. But, it did not modify the permissions of the mother folder from where I execute the command, 'the-theme-downloaded', taking into account that as a rule it should recursively.
When I check that folder of the downloaded theme through the file explorer ยซBoxยป, the first subfolders there appear with a padlock, and something absurd happens, I can copy any of those folders and paste it right there with all its content, being that it should be denied. And then when trying to delete said copy, you can't do it: permission denied, I suppose because all the subdirectories and files inside had their write permission removed, as I practiced.
I do not know if it is a Bug of the chmod command, the one that does not modify the permission of the folder from which the command is launched, and then the roll of being able to copy subdirectories that were configured without write permission.
In articles on the internet, including this one, he describes that these are the steps to get it recursively right.
I searched in English, to see if any option of the command was missing, but I did not find about it. However, I inducted from previous tests, that the command could be used like this 'chmod -Rv uw ./ *', and indeed, it modifies the permissions of the folder or directory from where I execute the command, the downloaded theme folder, despite that I haven't seen that './' option in using chmod.
If any connoisseur, please can elucidate me about my doubts.
Thank you.
If a user has write permissions and does not have read permissions on a file, can he modify the file?
Si
Another thing: the initials of the permits are wrong.
The r is for Read, and it stands for reading. Idem for writing.
excellent I finally understood it is well explained
I have a doubt with examples that they put
the example command: chmod -r 777
According to I remove the Read permissions to users, groups, others but the 777 (rwx) then what does it mean?
not serial equal k chmod ur, gr, or ????
Very good, I hope to continue learning Linux
Thanks a lot! Excellent contribution ...
excellent, thanks
Very good explanation, I was scratching myself with a partition where I couldn't modify files. Then I found out that I did not have ntfs-3g installed since it is an ntfs partition and solved.
Or a script (interpreter) that needs read and execute permission, a compiled program only needs to be read.
a "d" appears at the beginning of the user drwxr-xr-x. what does it mean? I guess it's directory but I'm not sure
Now we know the 3 permissions and how to add or remove these, but these 3 permissions are stored in 3 different places called
-r โ r โ rโ 1 wada users 4096 Apr 13 19:30 file?
If it is a program called "foo" we can execute it as any command. https://gswitch3.net
Nice this amazing post.
This is a kind of infumable scam. do not believe what I say.
hi everyone, i'm too new to this chmod topic, and chonw.
I apologize if I do not understand very well, I am trying to order all the examples to have a clarity of how to use the permissions, and assignments of the different groups, with permissions of rwx, read write execution, how to understand all the configuration well , of the files and folders, subdirectories when you execute the command ls -l the information that appears there, and the hyphens between each letter formulated there, also how to do that when you copy information from a disk using nautilus, that all the copied files appear including folders with a padlock, how to become the owner of all the information without changing the permissions of each of the files by default, to be able to read, write, execute, and delete whatever you want, without having to use root.
I have read and I have been a user who always executed chmod -R 777 file, or folders, because I have read it that way, but when you do a ls to said file, or folder then they are highlighted in a more intense green that the Name clearly, because I use linux mint, but I see that there may be another similar folder, with other attributes, and with a different color, just like the rest, now I read that 755, I don't know if it should be used in this way (chmod - R 755 Folder) leaves the permissions by default, to that folder, and it is for directories, but 644 is for files, I don't know if it's okay to use it this way (chmod -R 644 files), but when the ls is done - Then it appears that the file is 644, and in others it appears root, and others in the name of users, already with these results, something is out of the ordinary.
I don't have the slightest idea of โโhow to use the ideal commands, so that the folders, directories, and files have the necessary permissions that are needed, and are assigned to the groups, or users that I want
I want to learn to know what kind of files they are when doing an ls -l
drwxr-xr-x 2 root root 4096 Feb 15 22:32 a
-rwxrwxrwx 1 root root 474 Feb 16 23:37 canaima5
-rwxrwxrwx 1 root root 374 Feb 9 16:34 Error_EXFAT
drwxr-xr-x 3 root root 4096 Feb 15 00:22 windows installation USB
-rw-r โ rโ 1 m18 m18 7572 Dec 22 2016 mdmsetup.desktop
-rwxrwxrwx 1 root root 61 Feb 18 13:07 pkme
-rwxrwxrwx 1 root root 10809 May 15 2013 README
-rwxrwxrwx 1 root root 57 Jan 3 11:58 recover sudo
-rwxrwxrwx 1 root root 1049 Feb 18 01:02 Rep-Systemback
-rwxrwxrwx 1 root root 1163 Feb 11 11:12 root.txt
-rwxrwxrwx 1 root root 384 Feb 10 22:30 systemback ubuntu 16-18
-rwxrwxrwx 1 root root 31 Jan 1 2002 torregal
Here is an example I have tried to modify some files the m18 were created in a user, the rest was copied from another disk, with nautilus, and they have padlocks,
drwxr-xr-x 3 root root 4096 Feb 15 00:22 install windows USB
drwxr-xr-x 2 root root 4096 Feb 15 22:32 a have a padlock, the rest of the files also, but use this command from the information proving what happens: the files now do not have a padlock but, I don't know if they are ok The permissions they have, and the idea is to know what permission each file or folder should have, and in which group it should be. and know what to use when adding chmod.
m18 @ m18 ~ $ cd Desktop /
m18 @ m18 ~ / Desktop $ ls -l
Total 60
drw-r โ rโ 2 root root 4096 Feb 15 22:32 a
-rw-r โ rโ 1 root root 474 Feb 16 23:37 canaima5
-rw-r โ rโ 1 root root 374 Feb 9 16:34 Error_EXFAT
drw-r โ rโ 3 root root 4096 Feb 15 00:22 windows installation USB
-rw-r โ rโ 1 m18 m18 7572 Dec 22 2016 mdmsetup.desktop
-rw-r โ rโ 1 root root 61 Feb 18 13:07 pkme
-rw-r โ rโ 1 root root 10809 May 15 2013 README
-rw-r โ rโ 1 root root 57 Jan 3 11:58 retrieve sudo
-rw-r โ rโ 1 root root 1049 Feb 18 01:02 Rep-Systemback
-rw-r โ rโ 1 root root 1163 Feb 11 11:12 root.txt
-rw-r โ rโ 1 root root 384 Feb 10 22:30 systemback ubuntu 16-18
-rw-r โ rโ 1 root root Jan 31, 1 torregal
m18 @ m18 ~ / Desktop $ sudo ugo + rwx *
[sudo] password for m18:
sudo: ugo + rwx: command not found
m18 @ m18 ~ / Desktop $ sudo chmod ugo + rwx *
m18 @ m18 ~ / Desktop $ ls -l
Total 60
drwxrwxrwx 2 root root 4096 Feb 15 22:32 a
-rwxrwxrwx 1 root root 474 Feb 16 23:37 canaima5
-rwxrwxrwx 1 root root 374 Feb 9 16:34 Error_EXFAT
drwxrwxrwx 3 root root 4096 Feb 15 00:22 windows installation USB
-rwxrwxrwx 1 m18 m18 7572 Dec 22 2016 mdmsetup.desktop
-rwxrwxrwx 1 root root 61 Feb 18 13:07 pkme
-rwxrwxrwx 1 root root 10809 May 15 2013 README
-rwxrwxrwx 1 root root 57 Jan 3 11:58 recover sudo
-rwxrwxrwx 1 root root 1049 Feb 18 01:02 Rep-Systemback
-rwxrwxrwx 1 root root 1163 Feb 11 11:12 root.txt
-rwxrwxrwx 1 root root 384 Feb 10 22:30 systemback ubuntu 16-18
-rwxrwxrwx 1 root root 31 Jan 1 2002 torregal
m18 @ m18 ~ / Desktop $ sudo chmod -R 755 installation \ de \ windows \ USB /
m18 @ m18 ~ / Desktop $ ls -l
Total 60
drwxrwxrwx 2 root root 4096 Feb 15 22:32 a
-rwxrwxrwx 1 root root 474 Feb 16 23:37 canaima5
-rwxrwxrwx 1 root root 374 Feb 9 16:34 Error_EXFAT
drwxr-xr-x 3 root root 4096 Feb 15 00:22 windows installation USB
-rwxrwxrwx 1 m18 m18 7572 Dec 22 2016 mdmsetup.desktop
-rwxrwxrwx 1 root root 61 Feb 18 13:07 pkme
-rwxrwxrwx 1 root root 10809 May 15 2013 README
-rwxrwxrwx 1 root root 57 Jan 3 11:58 recover sudo
-rwxrwxrwx 1 root root 1049 Feb 18 01:02 Rep-Systemback
-rwxrwxrwx 1 root root 1163 Feb 11 11:12 root.txt
-rwxrwxrwx 1 root root 384 Feb 10 22:30 systemback ubuntu 16-18
-rwxrwxrwx 1 root root 31 Jan 1 2002 torregal
m18 @ m18 ~ / Desktop $ sudo chmod -R 755 a
m18 @ m18 ~ / Desktop $ ls -l
Total 60
drwxr-xr-x 2 root root 4096 Feb 15 22:32 a
-rwxrwxrwx 1 root root 474 Feb 16 23:37 canaima5
-rwxrwxrwx 1 root root 374 Feb 9 16:34 Error_EXFAT
drwxr-xr-x 3 root root 4096 Feb 15 00:22 windows installation USB
-rw-r โ rโ 1 m18 m18 7572 Dec 22 2016 mdmsetup.desktop
-rwxrwxrwx 1 root root 61 Feb 18 13:07 pkme
-rwxrwxrwx 1 root root 10809 May 15 2013 README
-rwxrwxrwx 1 root root 57 Jan 3 11:58 recover sudo
-rwxrwxrwx 1 root root 1049 Feb 18 01:02 Rep-Systemback
-rwxrwxrwx 1 root root 1163 Feb 11 11:12 root.txt
-rwxrwxrwx 1 root root 384 Feb 10 22:30 systemback ubuntu 16-18
-rwxrwxrwx 1 root root 31 Jan 1 2002 torregal
on the other hand knowing how to use the chown command. I also do not know if it is better to use the cp command to copy the information, from another hard drive with some wildcard that copies the files with all their permissions, and that they remain available to your user, or they always remain with the padlock
what I want is that if someone knows of a more complete article, and with examples of each of the wildcards, that use chmod, and chown. I can place it so that it is easier for newbies to learn, since there are tables where the 3-digit numbering appears, such as those of 777, 644, and how that numbering is formed, without they are predetermined, or there are many more that are reflected by the summation of ugo I do not know if it is right I think it is User, Group (s) Owners, and with the rwx for folders, subdirectories, executable files, etc.
in the end what I want is to learn to use all the formulas, of the chmod, and chonw for all the files, and for the entire linux file system
I apologize if my question on the subject is very ridiculous, I am just looking for some guidance, to have a more comfortable method of being able to understand each part of the group permissions, and the modifier commands, of the chmod, and chonw programs.
Greetings, and Thank you very much for your collaboration.
danny i love him uwu
danny i love him uwuโฆ.