WebDesires

How to change file and folder permissions in SSH

How to change file and folder permissions in SSH

Need Some Help? We are here for you!

We have a very friendly service - Come and chat to us and let us know what you need, we work for an hourly fee and can also provide you a no obligation quote and begin work immediately in most cases. Click "Request Support" or use our Live Chat.

Request Support
There is a mobile optimized version of this page, view AMP Version.

One of the most time consuming tasks any Server Administrator / Web Developer faces is changing file, folder and owner permissions across a whole project, if you have more than a few hundred files this can take quite a while using FTP commands. If you have SSH access to the server, you can quickly change file, folder and owner permissions across thousands of files in the matter of seconds, and its very easy to do if you know the commands. Because different servers have different permissions requirements, and of course the owner will be different, this is an example only and you should consult your server management team about the correct settings you need to use. However it should be noted that no server should require 777 for folders or 666 for files, as this is a major security risk to you and your server.  

Change file permissions with SSH

Below is the SSH command for changing all file permissions on a server, this command will run from the directory you are currently in and will go through all sub-directories changing permissions for files only. In this command we are changing the file permissions to 644 – which is the most common and safest setting.

find * -type f -exec chmod 644 {} ";"

 

Change folder permissions with SSH

Below is the SSH command for changing all folder permissions on a server, this command will run from the directory you are currently in and will go through all sub-directories changing permissions for folders only. In this command we are changing the folder permissions to 755 – which is the most common and safest setting.

find * -type d -exec chmod 755 {} ";"

 

Change owner of files and folders with SSH

Below is the SSH command for changing the owner on both files and folders recursively, the command will run from the directory you are currently in and will go through all sub-directories changing the owner for each file and folder. The command goes user:group, it is important you do not get the order mixed up as this will require you to run the command again and if you are not logged in as a root user you may lose access to the files. Note: You can either enter the names of the user/group or use the id’s, some FTP clients only display the user/group id which can be used in this function.

chown -R user:group *

Need Some Help? We are here for you!

We have a very friendly service - Come and chat to us and let us know what you need, we work for an hourly fee and can also provide you a no obligation quote and begin work immediately in most cases. Click "Request Support" or use our Live Chat.

Request Support

Author: Dean Williams

Professional PHP Web Developer with expertise in OpenCart Web Development, WordPress Web Development, Bespoke Systems - also a seasoned Linux Server Administrator.