What is Ownership Permission In Linux? How To Change It Via SSH?

What is Linux Ownership Permission?

In Linux, whoever creates a file or directory becomes the owner of it. Linux File Ownership has divided into three types:

User: A user is the one who created the file. Whoever creates a file becomes the owner of that file.

Group: A group can have multiple user access in it. A user who belongs to the same group (server), will have the same group permissions to any file.

Other: Other is everyone that is neither owner nor group member.

Only a root user can reassign the permissions. For example, a root can create a file and forward the ownership to you with the help of the chown command. Let’s see how it works practically.

ownership permissions in linux and how to change it

Why one should change the ownership permission?

Let me tell you the story that I personally faced recently. I was running a website from RedserverHost that was hosted on server 55. After using the same server (package) for a couple of months, I decided to change the server. I purchased reseller hosting with WHM (root) access and migrated my website from the old server to the new one. I did it successfully, the website was live from a different server but, when I tried to edit the file, I was facing an error that is called Permission Denied. 

Also See:

SSD vs HDD | Why SSD Hosting Is Better?

Permision denied error

Why did I get a Permission denied error while editing the file? Why I’m not able to edit my file because of the Permission denied error? This is because the ownership permission changed to root when I migrated the website from one server to another at the root level. If this was done at the user level, the permission denied error won’t come.

Now, to solve the Permission denied error, you can simply log into the SSH as a root and forward the ownership to the user. If this didn’t ring the bell, let me show you practically.

How To Change Ownership Permission in Linux Via SSH?

The ownership permission of a file can be changed by root only. The root user can easily change the user and/or group ownership permission of any file or directory via ssh using the chown command.

Before changing the ownership permission, you must know “How to view the ownership permissions of any file/directory?”.

Well, you can easily do it by adding the -all argument in the ls command. For example:

# ls -all

Output:

-rw-r--r-- 1 voiceofvictims voiceofvictims 277 Mar 16 11:58 .htaccess
-rw-r--r-- 1 voiceofvictims voiceofvictims 905 Mar 15 16:49 .htaccessnhh
-rw-r--r-- 1 root                root      405 Mar 15 16:30 index.php
-rw-r--r-- 1 root                root    19915 Mar 15 16:31 license.txt
drwxr-xr-x 5 root                root     4096 Mar 15 16:49 PHPmailertesting
-rw-r--r-- 1 root                root 38469398 Mar 15 16:00 PHPmailertesting.zip
-rw-r--r-- 1 root                root     7437 Mar 15 16:00 readme.html
        USER PERMISSION     GROUP PERMISSION

In this, I won’t be able to edit those files from cPanel that has user & group permission to root. To edit those files, you have to contact your hosting provider to forward the ownership to your username & you can do it yourself by following the below steps (if you’re a root user).

  • Log in to your SSH with root.

Login as root

  • Move inside the directory where you want to perform the changes by using the cd path/to/directory command.
  • Now use the ls -all command to view the user & group of every file/directory. Else, you can use the ls -ld command to view the ownership of a specific directory.

Change ownerhip permission

  • Use the chown user:group DirectoryName command & hit the enter button to change the ownership.

That’s how you can easily change user & group ownership of any file or directory via SSH. Other than this, if you only want to change the ownership of the group, or user, you can do it with the below command.


# chown USER FILE

Example:

# chown RSH NewFile

 

The above command will change the ownership of a file named NewFile to a new owner named RSH.


You can also change the owner permission of multiple files at once.

# chown RSH File1 Directory1 

The above command will change the ownership of a file named File1 and directory named Directory1 to a new owner named RSH.


You can use a user UID instead of a username that you can find by typing the cat /etc/passwd command.

# chown 0 File1

The above command will change the ownership of a file named File1 to a new owner, whose UID is 0 (Zero).

Find group and user id in linux


Zero (0) UID is pre-assigned to the root and you can see the rest by scrolling your cursor.

Moreover, you can use the grep command to find the username & its UID.

how to view group id and user id in linux


I hope this tutorial helps you somehow. If you’re facing any issues regarding the above commands. Feel free to hit the comment section. We’ll be happy to assist you.

Also See:

How to Check Current Running Processes in WHM?

Other than this, if you’re facing difficulties in using SSH, you can follow our detailed guide on Basic Linux Commands with live examples that will surely help you use SSH more efficiently.

Moreover, You can use our Reseller Hosting to enjoy root access. Or you can start your journey as a Web Hosting Provider with our Cheapest Reseller Hosting plans.

Scroll to Top