LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 11-11-2019, 12:48 PM   #1
Mulsimine
Member
 
Registered: Dec 2017
Distribution: Debian 9.5 Stable || DE: XFCE
Posts: 46
Blog Entries: 1

Rep: Reputation: 10
Question CHMOD Quesiton


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 *.*
 
Old 11-11-2019, 01:49 PM   #2
Nascentes
LQ Newbie
 
Registered: Nov 2019
Posts: 1

Rep: Reputation: Disabled
You can target folder only using find. eg.

Code:
~ [I] ➜ ls -lR test
total 0
drwxr--r--  3 myuser  staff  96 Nov 11 12:35 dir1
drwxr--r--  3 myuser  staff  96 Nov 11 12:35 dir2
drwxr--r--  3 myuser  staff  96 Nov 11 12:35 dir3

test/dir1:
total 0
-rwxr--r--  1 myuser  staff  0 Nov 11 12:41 testfile

test/dir2:
total 0
-rwxr--r--  1 myuser  staff  0 Nov 11 12:35 testfile

test/dir3:
total 0
-rwxr--r--  1 myuser  staff  0 Nov 11 12:35 testfile

~ [I] ➜ find test/ -type d -mindepth 1 -exec chmod 750 {} \;

~ [I] ➜ ls -lR test
total 0
drwxr-x---  3 myuser  staff  96 Nov 11 12:35 dir1
drwxr-x---  3 myuser  staff  96 Nov 11 12:35 dir2
drwxr-x---  3 myuser  staff  96 Nov 11 12:35 dir3

test/dir1:
total 0
-rwxr--r--  1 myuser  staff  0 Nov 11 12:41 testfile

test/dir2:
total 0
-rwxr--r--  1 myuser  staff  0 Nov 11 12:35 testfile

test/dir3:
total 0
-rwxr--r--  1 myuser  staff  0 Nov 11 12:35 testfile
Here is an AskUbuntu thread with some more examples and more detailed explanations: https://askubuntu.com/questions/7675...-for-a-website
 
Old 11-11-2019, 02:00 PM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Quote:
Originally Posted by Mulsimine View Post
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?
 
Old 11-11-2019, 02:32 PM   #4
Mulsimine
Member
 
Registered: Dec 2017
Distribution: Debian 9.5 Stable || DE: XFCE
Posts: 46

Original Poster
Blog Entries: 1

Rep: Reputation: 10
Quote:
Originally Posted by Nascentes View Post
Here is an AskUbuntu thread with some more examples and more detailed explanations: https://askubuntu.com/questions/7675...-for-a-website
This is helpful, thank you very much =)


Quote:
Originally Posted by scasey View Post
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 View Post
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 View Post
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.

Last edited by Mulsimine; 11-11-2019 at 02:33 PM.
 
Old 11-12-2019, 12:15 AM   #5
rnturn
Senior Member
 
Registered: Jan 2003
Location: Illinois (SW Chicago 'burbs)
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Quote:
Originally Posted by Mulsimine View Post
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.
What did you use to perform the backup? Most backup software can preserve file/directory permissions and restore them during a restore.

HTH...
 
Old 11-12-2019, 06:47 AM   #6
Mulsimine
Member
 
Registered: Dec 2017
Distribution: Debian 9.5 Stable || DE: XFCE
Posts: 46

Original Poster
Blog Entries: 1

Rep: Reputation: 10
Quote:
Originally Posted by rnturn View Post
What did you use to perform the backup?
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.

Code:
mysqldump -u JimmyUSER -pJimmyPW JimmyDB > DB-backups/$(date +\%m-\%d-\%Y-\%H.\%M.\%S)-JIMMY-db.sql
 
Old 11-18-2019, 03:17 AM   #7
nelz
Member
 
Registered: Aug 2004
Posts: 34

Rep: Reputation: 6
Why not simply use "chmod -R +X ." after setting all to 644?
 
Old 11-18-2019, 08:56 AM   #8
Mulsimine
Member
 
Registered: Dec 2017
Distribution: Debian 9.5 Stable || DE: XFCE
Posts: 46

Original Poster
Blog Entries: 1

Rep: Reputation: 10
Quote:
Originally Posted by nelz View Post
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
 
Old 11-18-2019, 10:03 AM   #9
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by nelz View Post
Why not simply use "chmod -R +X ." after setting all to 644?
because that would make everything 755

Quote:
Originally Posted by Mulsimine View Post
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
 
1 members found this post helpful.
Old 11-18-2019, 10:14 AM   #10
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by Firerat View Post
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.
 
1 members found this post helpful.
Old 11-18-2019, 10:31 AM   #11
jsbjsb001
Senior Member
 
Registered: Mar 2009
Location: Earth, unfortunately...
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881

Rep: Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063Reputation: 2063
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache: difference between chmod 644 and chmod 666 and chmod 600 for output/txt/dat? frenchn00b Programming 6 04-22-2009 01:10 PM
chmod, external usb, vfat - can't chmod a directory itsjustme Slackware 2 04-02-2006 04:23 PM
What can we do if we type chmod ugo-x /bin/chmod ?????? bunny123 Linux - Software 3 02-01-2005 08:53 PM
CHMOD in shell : chmod 777 /usr/ <---is that right? cpanelskindepot Programming 5 07-16-2004 05:37 AM
chmod +s or chmod -s excel28 Linux - General 1 09-30-2003 03:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration