127 lines
2.9 KiB
Org Mode
127 lines
2.9 KiB
Org Mode
#+options: toc:nil num:nil author:nil
|
|
|
|
* Changing permissions for files and directories
|
|
|
|
There are three types of permissions for files and directories in the system:
|
|
|
|
1. Read ('r')
|
|
2. Write ('w')
|
|
3. Execute ('x')
|
|
|
|
The permissions can be differente for users: owner - group - others
|
|
|
|
** Creating a file and checking permissions
|
|
|
|
Here we create a file with the sentence "this is a fancy file". The sentence is
|
|
redirected to the name "fancyfile.org" and a new file is created!
|
|
|
|
#+begin_src bash
|
|
echo "this is a fancy file" > fancyfile.org
|
|
#+end_src
|
|
|
|
#+RESULTS:
|
|
|
|
In the ouptut of ~ls~ command, there letters showing each permission for each user: owner, group, others, respectively.
|
|
|
|
#+begin_src bash
|
|
ls -la fancyfile.org
|
|
#+end_src
|
|
|
|
#+RESULTS:
|
|
: -rw-r--r-- 1 compartido compartido 21 jul 18 06:06 fancyfile.org
|
|
|
|
** Settings permissions for the file
|
|
|
|
#+begin_src bash
|
|
chmod o=r,g=rw,o=r fancyfile.org
|
|
#+end_src
|
|
|
|
#+RESULTS:
|
|
|
|
Then it changed!
|
|
|
|
#+begin_src bash
|
|
ls -la fancyfile.org
|
|
#+end_src
|
|
|
|
#+RESULTS:
|
|
: -rw-rw-r-- 1 compa user 21 jul 18 06:06 fancyfile.org
|
|
|
|
|
|
** Changing permission for directories
|
|
|
|
Let's say I (unintentionally) changed the permissions for a directory that
|
|
contains multiple subdirectories. Let's call that directory "buds"
|
|
|
|
I can't access the files without being `root`. This is the outuput in the
|
|
command line When a list the directory using `ls -la`.
|
|
|
|
|
|
#+begin_example bash
|
|
drw-r--r-- 81 user user 4096 dec 26 06:21 buds
|
|
#+end_example
|
|
|
|
When I go to my git repository and check the change I can see this output for
|
|
every file within the directory:
|
|
|
|
#+begin_example bash
|
|
diff --git a/doc/index.rst b/doc/index.rst
|
|
old mode 100644
|
|
new mode 100755
|
|
#+end_example
|
|
|
|
|
|
This is how the permission could be changed:
|
|
|
|
Note that, in this case, it's necessary to use `sudo` before the command to
|
|
access the files
|
|
|
|
#+begin_src bash
|
|
chmod -R o=wxr,g=xr, o=x buds
|
|
#+end_src
|
|
|
|
This will change the permissions for:
|
|
|
|
* The owner (4 = read; 2 = write; 1 = execute)
|
|
* The group (4 = read) and
|
|
* Others (4 = read)
|
|
|
|
Use ~-R~ if you want to apply recursive ~chmod~
|
|
|
|
#+begin_src bash
|
|
chmod 744 NameOfFileHere
|
|
#+end_src
|
|
|
|
Think of the following code: what does that code do?
|
|
|
|
#+begin_src bash
|
|
chmod -R 755 NameOfFileHere
|
|
#+end_src
|
|
|
|
*** The output now is:
|
|
|
|
#+begin_example bash
|
|
drw-r-x--x 81 user user 4096 dec 26 06:21 buds
|
|
#+end_example
|
|
|
|
Remember how it looks before
|
|
|
|
#+begin_example bash
|
|
drw-r--r-- 81 user user 4096 dec 26 06:21 buds_before
|
|
#+end_example
|
|
|
|
But I still can open the files. That is because need to change the owner:
|
|
|
|
#+begin_example bash
|
|
chown NameOfownerHere buds # Try this and check the result
|
|
#+end_example
|
|
|
|
Include the owner then ~:~ and then the name of the group to change ownership for each one of those users
|
|
|
|
#+begin_example bash
|
|
chown user:usergroup buds # Then try this and check the result
|
|
#+end_example
|
|
|
|
|
|
ps: should use`sudo` to run this command, so be careful and make a scratch directory
|
|
to run tests.
|