Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've SSH'ed into my webhost. I've restored a website backup and need to reset all permissions for the files and folders there. I figured out how to change all file permissions, but I cannot figure out how to target only folders. Can it be done?
This is what I used for changing all file permissions: (executed from the homedir)
I've SSH'ed into my webhost. I've restored a website backup and need to reset all permissions for the files and folders there. I figured out how to change all file permissions, but I cannot figure out how to target only folders. Can it be done?
This is what I used for changing all file permissions: (executed from the homedir)
Code:
chmod -R 644 *.*
That would change the permissions on folders (directories) to...and prevented them from being readable...
From the homedir
Code:
find . -type d -exec chmod 755 {} \;
See man find
Although I have to ask. If you're working with a restored backup of the website, why do you need to reset permissions?
That would change the permissions on folders (directories) to...and prevented them from being readable...
I'm glad I posted that code here then. Good to know!
Quote:
Originally Posted by scasey
From the homedir
Code:
find . -type d -exec chmod 755 {} \;
See man find
This did the trick. Thank you very much!
Quote:
Originally Posted by scasey
Although I have to ask. If you're working with a restored backup of the website, why do you need to reset permissions?
Cpanel has a "Backup" section. I performed a Full Backup but when I restore it the permissions for files are all over the place. They are not how they were set when I backed it up.
When I manually upload the files from the backup Full Backup generated, via FTP, they do have the correct permissions. However, I have different problems with that route. When I try to upload files via Filezilla FTP Client, I am repeatedly told that the file already exists, and what I want to do about it? Sometimes the file has a real file size, other times the file size is 0 bytes.
No idea why this is happening and this is not normal behavior for interacting with my website. If I tell it to overwrite all files it encounters, it will finish with 115 files failed. Upon checking, none of these files exist on the server. If I tell it to re-queue the files on the Failed list, it tells me that not all files could be re-queued and it clears the Failed file list.
This isn't normal behavior for Filezilla, so I'm not too worried about investigating it further right now. So I turn back to Cpanel. I am unable to upload these files using File Manager in Cpanel, as it will only allow me to upload a single file at a time. That is inefficient, tedious, and time consuming. So that leaves me with only the Cpanel backup restore tools which were responsible for assigning the incorrect permissions.
I sought out SSH approach to try tackling the file permissions at a faster rate than Cpanel's File Manger allowed me.
Cpanel has a "Backup" section. Within that section you can make a "Full Backup", as well as restore a backup. When I restore the Full Backup I made there, the permissions for files are all over the place. They are not how they were set when I backed it up. This method is temporary. I had planned to setup a cron job to do the backing up, but had not gotten around to it. Something happened, and I had no choice but to restore a backup made using Cpanel.
After this experience I set out to find how to create the cron job to create backups. I came across this article, which provides the following solution:
Files Backup Cron Job
Quote:
This command will tar all files in the public_html folder and create an archive in the FILES-backup folder using today’s date/time.
Code:
tar -zcf FILES-backup/"$(date '+\%m-\%d-\%y').tar.gz" public_html
Database Backup Cron Job
Quote:
This command will dump a MYSQL database in the FILES-backup folder using today’s date/time. In this example, hosting username and password is Jimmy and JimmyPW, while your database name is JimmyDB. The resulting file will be saved in the DB-backups folder.
Why not simply use "chmod -R +X ." after setting all to 644?
I was not aware of this. I am very new to Linux and the command line. I looked this up and it looks awesome. I will definitely use this in the future. Thank you
Why not simply use "chmod -R +X ." after setting all to 644?
because that would make everything 755
Quote:
Originally Posted by Mulsimine
I was not aware of this. I am very new to Linux and the command line. I looked this up and it looks awesome. I will definitely use this in the future. Thank you
it was bad advice, don't use it unless you really want to set everything executable
it was bad advice, don't use it unless you really want to set everything executable
It is a valid command, however doing any command and not understanding the impact of it is what I'd consider to be a bad situation. To be clear, I concur with the cautious advice here.
@Mulsimine,
What you really need to understand is how file and directory privileges work and what the chmod command does with them, as well as other "ch" commands you may encounter.
I do feel that understanding the number 755 or variations of that, and what they mean, such as rwxrwxrwx translates to read/write/execute permissions for: owner, group, and world is important. Yes you can use +X, +W, or +R, and also - for each of those, along with some others, and you also can use the numbers. You can perform the command recursively using the -R argument. But you really should understand what impact it is going to have on your files when you do this.
I think you should look at some chmod tutorials on the web. I found a few with that search string, and recommend you review some of them to understand just exactly what file permissions is all about, versus entering recommended commands by LQ users. The recommendations may be valid, they may help you now, but if you do not understand how they helped you, this would seem to be a problem I'd be more concerned about.
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881
Rep:
Mulsimine, you can look at the Wikipedia article about file permissions under the "Numeric notation" heading. It's also known as "octal notation", and it's easier than you might think. Basically a "4" is equal to "read permission", a "2" is equal to "write permission", with a "1" being equal to "execute permission". So "600" would give the owning user of said file both "read" and "write" permissions. Why? Because what's 4 + 2 ? 6.
Here's a quick example;
Code:
james@jamespc: ~> touch test
james@jamespc: ~> chmod 000 test
james@jamespc: ~> ls -la test
---------- 1 james james 0 Nov 19 02:52 test
james@jamespc: ~> chmod 400 test
james@jamespc: ~> ls -la test
-r-------- 1 james james 0 Nov 19 02:52 test
james@jamespc: ~> chmod 200 test
james@jamespc: ~> ls -la test
--w------- 1 james james 0 Nov 19 02:52 test
james@jamespc: ~> chmod 100 test
james@jamespc: ~> ls -la test
---x------ 1 james james 0 Nov 19 02:52 test
james@jamespc: ~> chmod 600 test
james@jamespc: ~> ls -la test
-rw------- 1 james james 0 Nov 19 02:52 test
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.