Mass File Permissions Change via SSH

Dec 8

in Server Management / 0 comments

After gaining access to SSH to our snazzy Media Temple server, we’ve spent a few hours configuring it for a better performance. There is a great article on optimising the DV servers, however it is probably best for those more familiar with server management.

We transferred several sites across via the scp command, we found that the permissions & owner remained that of the old server. After extracting a site, we found all of the file permissions where wrong.

Luckily Media Temple provide a script on changing permissions.  The script:

find . -type f \ \( -iname "*.css" \ -or -iname "*.htm*" \ -or -iname "*.jpeg" \ -or -iname "*.jpg" \ -or -iname "*.gif" \ -or -iname "*.png" \ -or -iname "*.js" \ -or -iname "*.mpeg" \ -or -iname "*.mpg" \ -or -iname "*.mp3" \ -or -iname "*.avi" \ -or -iname "*.txt" \ -or -iname "*.doc" \ -or -iname "*.pdf" \ \) -exec chmod 644 {} \;

find . -type f \ \( -iname "*.php*" \ -or -iname "*.cgi" \ -or -iname "*.pl" \ -or -iname "*.py" \ -or -iname "*.rb" \ \) -exec chmod 700 {} \;

find . -type d -exec chmod 755 {} \;

As would any copy-paste’aholic, we found we were getting an error message. I examined the script, removed the \ before each -or statement and the \ after the -type f. This will now hopefully work for you. We have summerised the new code below:

find . -type f \( -iname "*.css" -or -iname "*.htm*" -or -iname "*.jpeg" -or -iname "*.jpg" -or -iname "*.gif" -or -iname "*.png" -or -iname "*.js" -or -iname "*.mpeg" -or -iname "*.mpg" -or -iname "*.mp3" -or -iname "*.avi" -or -iname "*.txt" -or -iname "*.doc" -or -iname "*.pdf" \) -exec chmod 644 {} \;

find . -type f \( -iname "*.php*" -or -iname "*.cgi" -or -iname "*.pl" -or -iname "*.py" -or -iname "*.rb" \) -exec chmod 700 {} \;

find . -type d -exec chmod 755 {} \;

The extra slashes come from the editor hoping to escape certain characters on the Media Temple Wiki.

Add your comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>