The world of Linux is different from Windows, and can be daunting for new users. Where Windows uses a graphical user interface (GUI) for the majority of the OS, Linux relies much more heavily on Terminal, a type of command-line interface (CLI) for UNIX-based OSs.

While daunting at first, this CLI holds immense potential for customisation and granular control over the OS, something where Windows is lacking. With enough knowledge, you can operate solely within the CLI and entirely forgo a GUI on Linux (a standard option in distributions like Debian and Red Hat).

When using Terminal, you have the option of manually editing file properties with the chmod command. This command allows you to assign read, write, and execute permissions for individual files. These permissions can apply to a single root user, a user group, or a networking group on home and business domains.

Let us explore how to get started with chmod, and the uses it has in the real world. Please note we are using Ubuntu 18.04 LTS for these examples, so shortcuts and terminologies may vary if you are using a different Linux distribution.

Using chmod for the first time

Firstly, chmod stands for ‘change mode’. In this case, you are changing the permissions mode for files using chmod.

To get started with chmod, you need to open a terminal window. To do this, press Ctrl+Alt+T on your keyboard, or search for Terminal in your GNOME App Launcher.

You can type a variety of commands aside from chmod into this window, but we will be exploring chmod today. While you can use chmod on any file you wish, we recommend making a test.txt file to experiment with. The easiest way to create a .txt file is by opening Text Editor from GNOME, and clicking Save in the top right of the window. Remember to add .txt onto the file name, as Linux does not automatically assign this extension in the same way Windows does.

Editing permissions with chmod

We saved the test.txt file to our Home directory location, the default for Ubuntu.

In your terminal window, type cd /home/YOUR_USERNAME to navigate to the /home directory on your hard drive. If your test document is in another location, open the Files application (similar to File Explorer in Windows) and find the document. Right-click on the document you created, go to Properties, then copy and paste the Parent Folder attribute into the terminal window as your chosen location (remember to put cd before the folder location, as shown at the start of this paragraph).

Now, you can run commands on any folder or item in this directory location.

The chmod command starts with chmod, followed by three numbers, then the file or folder name:

chmod 755 test.txt

The three numbers denote the following:

First Digit – this is the file owner, which could be the Ubuntu root user or an FTP user for remote connections. The first digit, therefore, dictates what permissions the file owner has

Second Digit – all users on a Linux-based system are assigned to a group. This could be sudo (root admin), testuser (or your username), and sambashare for local area network (LAN) sharing

Third Digit – this is for any external user unrecognised by your Linux OS. Unless you are hosting a public-facing server, we recommend always using 0 to deny access to these users. This will prevent all unauthorised access to your files. By using 7, you allow any user with a connection to your machine access to your files, posing a huge security risk

Next, we will explain what numbers to put here and what they do:

• 0 – No permissions. Denies read, write, and execution permissions.
• 1 – Read and write not allowed. Only the execution of the file is permitted.
• 2 – Read and execute not allowed. Only write is permitted.
• 3 – Read not allowed. Only write and execute are permitted.
• 4 – Write and execute not allowed. Only read is permitted.
• 5 – Write not allowed. Read and execute are permitted.
• 6 – Execute not allowed. Read and write are permitted.
• 7 – Read, write, and execute are all permitted. Take care with this option, as it may pose a security risk.

Now we can understand and decipher what the earlier command means.

We asked chmod to assign read, write, and execute permissions to the File Owner (7).

By going to Properties for the test.txt file, we can see the assigned group. This is under Permissions, and the group will be in the dropdown box next to ‘group’ in this window. We asked chmod to assign read and execute permissions, but not write permissions to the group in question (5).

Finally, for any other unspecified user, we gave the same read and execute permissions, but not write permission (5). This means any external user connected to this machine will be able to read the file contents and execute the file.

Advanced chmod Usage

While a number system is easier for getting started with chmod, many advanced users would use rwx. This denotes read, write, and execute, much in the same way the aforementioned numbers do.

Instead of the three digits, advanced chmod uses ugo.

u = user
g = group
o = others

To assign permissions to ugo, you would use + to grant permission, or to remove permission.

As an example:

Chmod u+rwx,g+rx,o+rx test.txt

This command will assign the user read, write, and execute permissions. The group and others will get read and execute permissions.

Real-world uses for chmod

Now that we understand how to assign permissions with chmod, what should we use this command for?

One example could be a home Network Access Server (NAS). You may be hosting video or audio files and streaming them to other systems on your LAN. Since users will be downloading the file to their own system and executing them locally, they will only need read permissions for these files.

In this case, you would type chmod 744 test.mp4 (mp4 is a video file type) to assign read-only permissions to non-owners. This helps to ensure that files are left unchanged by anyone but the NAS admin user.

Getting started on Linux with Fasthosts

The world of Linux can significantly increase the functionality and granularity of control available to you when using computer systems. For that reason, Fasthosts offers Linux Dedicated Servers to provide maximum functionality with minimal fuss. You can choose from a variety of Linux distributions, such as CentOS, Debian, and Ubuntu, and we are also offering 50% off the first three months of dedicated server usage to new and existing customers.

Get started with Linux by contacting our friendly sales team at Fasthosts on 0808 1686 777, or visit the Fasthosts website to find out more about our services today.