FUNDAMENTALS A Complete Guide for Beginners
In Ubuntu, permissions restrict access to files and directories. There are three categories of users for whom permissions can be set: the file’s owner, the members of the group that owns the file, and all others. Changing the file permissions to 777 will allow all users of the file to read, write and execute the file. In this tutorial, I will discuss how to change file permissions to 777 in Ubuntu.
Process Flow Chart to Change File Permission to 777Distro Used Throughout the Tutorial: Ubuntu 22.04.1 LTS
Read, Write & Execute Permissions in Linux
File and directory permissions are used in Linux to control resource access. Read, write, and execute permissions, which are denoted by the letters “r,” “w,” and “x,” respectively, are three basic forms of permissions. These permissions can be assigned to 3 types of users: the file or directory’s owner, the group that owns the file or directory, and others.
- Read permission (r): Allows a user to view the contents of a file or lists of a directory, but cannot modify them.
- Write permission (w): Allows a user to modify the contents of a file or to create, delete, or rename files in a directory. For example, a user with only written permission on a file can modify its contents but can’t view or execute it.
- Execute permission (x): Allows a user to run an executable file or change into a directory, but can not view or write onto it.
Read, write, and execute permissions can be represented using either octal or binary numbers. Here is a table below showing octal representation, binary representation, file permission set, and corresponding permissions of any file/directory.
Octal Representation | Binary Representation | File Permission Set |
Permission |
||
---|---|---|---|---|---|
0 | 000 | – – – | No permission | ||
1 | 001 | – -x | Execute | ||
2 | 010 | -w- | Write | ||
3 | 011 | -wx | Write | Execute | |
4 | 100 | r- – | Read | ||
5 | 101 | r-x | Read | Execute | |
6 | 110 | rw- | Read | Write | |
7 | 111 | rwx | Read | Write | Execute |
Steps to Change File Permissions to 777 in Ubuntu
You can change file permissions to 777 in Ubuntu. This will assign read, write, and execute permission to the three types of users. Here, I am using the file Summer to change its permissions to 777. Follow the step-by-step instructions below for a better understanding:
- Start by pressing CTRL+ALT+T to open the Ubuntu Terminal.
- To view the current permissions of the Summer file, run the following command in the command prompt:
ls -l
As you can see, the output shows the file permissions.EXPLANATION- ls: Shows all the files in a specific folder.
- option -l: Long listing format.
- To change the permissions to 777, execute the following command in the command prompt:
chmod 777 Summer
EXPLANATION- chmod: Changes file permissions.
- 777: Read, Write & Execute Permission.
- Summer: The file to change permission.
- Finally, run the command below to check if the permissions of the Summer file are changed.
ls -l
As you can see in the image above, the permissions of the file Summer are changed to 777 using the chmod command.
Change Permission of Directory and Subdirectory Using the “chmod” Command Recursively
You can change a directory and subdirectory’s permission at once using the chmod command in recursive mode. For this, you need to add the -R option to the chmod command. You can do this by following the procedure below:
- Open the Terminal in Ubuntu.
- To view the current permissions of the Summer directory and its subdirectory Fruits, run the following commands in the command prompt:
ls -l
ls -l Summer
In the image above, you can view the current permission of the Summer directory.In the snapshot above, you can view the current permission of the subdirectory Fruits of the Summer directory.EXPLANATION- Summer: The folder to change permission.
- To change the permission of the directory and subdirectory concurrently, execute the following command in the command prompt:
chmod -R 764 Summer
EXPLANATION- chmod: Changes file permissions.
- -R option: Enables recursive mode.
- 764: Read, Write & Execute Permission.
- Summer: The folder to change permission.
- Finally, run the following commands to check if the permissions of the Summer directory and Fruits subdirectory are changed:
ls -l
ls -l Summer
As you can see in the image above, the permission of both the directory and subdirectory changed at the same time with a single command.
Change Ownership of File in Linux
You can change a file’s ownership using the chown command in Ubuntu. You can change the ownership to a specific user, specific group, or both the user and the group. I have shown you how you can change the ownership of a file to these user types below.
Change the Ownership of a File to a Specific User in Linux
You can change the ownership of a file to a specific user in Ubuntu. Here I am changing ownership of myfile.txt from user sylvie to user rynvie. Follow the process below to do that:
- Open the Ubuntu Terminal.
- To view the current owner/user of the file myfile.txt, run the following command in the command prompt:
ls -l
In the image above, you can view the file with its current owner’s name.
- To change the ownership of the file to a specific user, execute the following command in the command prompt:
sudo chown rynvie myfile.txt
- Then, type the password and press the ENTER button.
- Finally, execute the following command to check if the ownership of the myfile.txt file is changed:
ls -l
As you can see, the ownership of the file is changed.
- How to Give Permission to User in Linux? [4 Methods]
- 2 Ways to Change Folder Permissions from Root to User in Linux
- How to Change Folder Permissions in Linux? [2 Methods]
- 2 Ways to Change Folder Permissions Recursively in Linux
Change the Ownership of a File to a Specific Group in Linux
You can change the ownership of a file to a specific group in Ubuntu. Here I am changing ownership of myfile.txt from group sylvie to group rynvie. Follow the procedure below to do that:
- Open the Terminal in Ubuntu.
- To view the current group of the file myfile.txt, run the following command in the command prompt:
ls -l
In the snapshot above, you can view the file with its current group’s name.
- To change the ownership of the file to a specific group, execute the following command in the command prompt:
sudo chown :rynvie myfile.txt
EXPLANATION- sudo: Grants administrative privileges.
- chown: Changes the file’s ownership.
- rynvie: name of the group.
- myfile.txt: The file to change ownership.
- Then, type the password and press the ENTER button.
- Finally, execute the following command to check if the group of the myfile.txt file is changed:
ls -l
As you can see, the ownership of the file is changed.
Change Both the User and Group Ownership of a File in Ubuntu
You can change both the user and group ownership of a file in Ubuntu. Here I am changing both the user and group ownership of myfile.txt from sylvie to rynvie. Follow the instructions below to do that:
- Initially open the Ubuntu Terminal.
- To view the current owner/user and group of the file myfile.txt, run the following command in the command prompt:
ls -l
In the image above, you can view the file with its current owner and group name.
- To change both the user and group ownership of a file, execute the following command in the command prompt:
sudo chown rynvie:rynvie myfile.txt
EXPLANATION- sudo: Grants administrative privileges.
- chown: Changes the file’s ownership.
- rynvie: name of the user and group.
- myfile.txt: The file to change ownership.
- Then, type the password and press the ENTER button.
- Finally, execute the following command to check if the ownership of both the user and group of the myfile.txt file are changed:
ls -l
As you can see, the ownership of the file is changed.
Conclusion
The chmod command can be used in Ubuntu to change file permissions to 777. Setting file permissions to 777 can be a security issue because it allows anyone to change or execute the file. It is best recommended to set the file permissions to the bare minimum needed to finish the task.
People Also Ask
What are the 3 types of permissions?
In Linux, there are three different permission types: read, write, and execute. These permissions determine what operations can be performed on a file or directory.
What do the letters in the chmod command mean?
The letters in the chmod command stand for the various operations and permission levels. The initial three letters, “u,” “g,” and “o,” stand for the owner, the group, and the others, respectively. The second letter ‘r’, ‘w’, and ‘x’ indicate read, write, and execute permissions. The third letter ‘+’ and ‘-‘ are used to add and delete permissions.
How do I change file permission to 777 in Ubuntu?
To change a file permission to 777, type the command chmod 777 followed by the filename you want to change the permission of and press ENTER. For example: to change the permission of the file named script.sh to 777, run the command chmod 777 script.sh
using the command prompt.
How do I give read/write access to a specific user on a file?
To give a specific user read/write access to a file, use the “chown” command to change the file’s ownership to that user, then use the “chmod” command to give that user read and write permissions.
How do I change the owner of a file in Linux?
To change the owner of a file in Linux, use the “chown” command, followed by the new owner’s username and the file name. For instance, sudo chown newOwner fileOne
would make newOwner the owner of fileOne.
How do I view the current permissions of a file in Linux?
To view the current file permission, use the ls
command, followed by the -l
option and the file name, to view the current permissions of a file. This will show a detailed list of the file’s information, including the owner, group, and others and their respective permissions.
How do I add execute permission to a file in Linux?
In Linux, use the “chmod” command, followed by the permission level and the file name, to add execute permission to a file. For instance, sudo chmod +x fileOne
would give the file “fileOne” execute permission.
How do I set default permissions for newly created files in a directory?
You can use the “umask” command followed by the desired permissions to specify default permissions for newly created files in a directory. For instance, umask 002
would change the default permissions to allow read, write, and execute permissions for the owner and group, and read and execute permissions for others.
Related Articles
- How to Change Permissions of All Files in a Folder in Linux?
- Manage File Permissions in Ubuntu Using Command?
- How to Change File Permissions in Linux? [6 Examples]
- 2 Cases to Give User Permission to Folder and Subfolders in Ubuntu
- How to Change Directories and Files Recursively with “chmod”
- Change Permissions on Mounted Drive in Linux