Managing file permissions

We have created users and groups. In this recipe, you will work with default file permissions for users and groups, as well as see how to modify those permissions.

Getting ready

Create two users, user1 and user2. Create new group editor and add user1 and user2 as members.

How to do it…

Follow these steps to manage file permissions, follow these steps:

  1. To change groups for files and directories:
    1. Log in with user1.
    2. Create a new directory documents under home:
      	user1@ubuntu:~$ mkdir documents
      
    3. Create a text file under documents:
      	user1@ubuntu:~$ echo "hello world"> documents/file.txt
      
    4. Now log in with user2:
      	user1@ubuntu:~$ su user2
      
    5. Try to edit the same text file. It should say Permission denied:
      user2@ubuntu:/home/user1$ echo "hello ...

Get Ubuntu Server Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.