Server Apache - Change only file but not folder (and vice versa) - apache

With this command I can set all file and folder in "img" to 0775:
chmod 775 -R /var/www/site.com/img/
But would I like change only the file inside the folder img; how can I do?
And for change only the folders?
Thanks

ok,
To recursively change dirs or files rights
find /root/path -type d -print0 | xargs -0 chmod 755
find /root/path -type f -print0 | xargs -0 chmod 644

Related

find: missing argument to `-exec' in SSH command

I'm using SSH inside a CI/CD Pipeline (so it's non-interactive), and trying to execute a couple find command (among others) to change the ownership of files and directories after executing LFTP mirror, but I keep getting this error (which makes the whole Pipeline fail):
find: missing argument to `-exec'
This is the command that uses find:
ssh -i ~/.ssh/id_rsa $USERNAME#$HOST "[other commands...]; find $SOME_PATH/ -type d -exec 'chmod 755 {} \;' && find $SOME_PATH/ -type f -exec 'chmod 644 {} \;' && echo Done"
I've already tried using escaped double quotes like so: -exec \"chmod 755 {} \;\" - but keeps throwing the same error.
What would be the main issue here?
EDIT: Solved. I removed any quotes for the -exec, removed the && and append an extra semicolon ; to each find and it works as expected.
ssh -i ~/.ssh/id_rsa $USERNAME#$HOST "[other commands...]; find $SOME_PATH/ -type d -exec chmod 755 {} \;; find $SOME_PATH/ -type f -exec chmod 644 {} \;; echo Done"
So use -exec whatever-command {} \;; [other command, echo, find, ls, whatever...].
Please check this answer for more information: https://unix.stackexchange.com/a/139800/291364
[...] When find sees that spurious exit after the -exec … ; directive, it doesn't know what to do with it; it hazards a (wrong) guess that you meant it to be a path to traverse. You need a command separator: put another ; after \; (with or without a space before). [...]
\; is processed to ; locally before the string is passed to the remote shell. You need to escape the backslash so the the ; remains escaped on the remote end.
ssh -i ~/.ssh/id_rsa $USERNAME#$HOST \
"[other commands...]; find $SOME_PATH/ -type d -exec 'chmod 755 {} \\;'
&& find $SOME_PATH/ -type f -exec 'chmod 644 {} \\;' && echo Done"
A better idea would be to use single quotes for the command argument and pass the value of $SOME_PATH as an argument to a shell.
ssh -i ~/.ssh/id_rsa $USERNAME#$HOST \
sh -c '...;
find "$1" -type d -exec chmod 755 {} \; &&
find "$1" -type f -exec chmod 644 {} \; &&
echo Done' _ "$SOME_PATH"
Note that chmod and its arguments each need to be separate arguments to the find.
In fact, you don't need to run find twice; you can provide two -exec primaries, each paired to a different -type:
ssh -i ~/.ssh/id_rsa $USERNAME#$HOST \
sh -c '...;
find "$1" \( -type d -exec chmod 755 {} \; \) -o
\( -type f -exec chmod 644 {} \; \)
&& echo Done' _ "$SOME_PATH"
Rather than the complex find commands (and associated quoting/escaping mess), you can use the built-in capabilities of chmod sympolic modes to set the permissions on files and directores differently. Specifically, the "X" permission means essentially "execute if it makes sense", which mostly means directories rather than files. The main exception is that if there's a file that already has execute set, it assumes it's intentional and keeps it. If that's ok, you can use this simpler command:
chmod -R u=rwX,go=rX "$1" # Set non-executable files to 644, executables and directories to 755
If you need to specifically clear execute bits on files, or just want to stick with find, another option take advantage of the fact that chmod accepts multiple arguments to use find ... -exec ... {} + instead of the \; version. "+" isn't a shell metacharacter, so it doesn't reqire special treatment:
find $SOME_PATH/ -type d -exec chmod 755 {} + ; find $SOME_PATH/ -type f -exec chmod 644 {} +

Magento emails not working error log 403

All emails in my Magento 1.9.2.4 shop : invoice , new registration , contact us.... not work. I recive error log 403.
I haven't make any changes on the site. Can the reason be in the cPanel?
You can run the following commands:
find ./ -type f | xargs chmod 644
find ./ -type d | xargs chmod 755
chmod -Rf 777 var
chmod -Rf 777 media

Count number of files in directory then scp transfer a certain range such as 21404-42806

I found the number of files in /dev/shm/split/1/ to be 42806 using:
/bin/ls -lU /dev/shm/split/1/ | wc -l
What I can't seem to find anywhere online is how to select a certain range, say from 21404-42806, and use scp to securely copy those files. Then, for management purposes, I would like to move the files I copied to another folder, say /dev/shm/split/2/.
How do I do that using CentOS?
I tried:
sudo chmod 400 ~/emails/name.pem ; ls -1 /dev/shm/split/1/ | sed -n '21443,42806p' | xargs -i scp -i ~/emails/name.pem {} root#ipaddress:/dev/shm/split/2/
This produced:
no such file or directory
errors on all of the files...
ls itself lists files relative to the directory you give. This means your ls prints the filenames in the directory, but later on, scp doesn't have the path to them. You can fix this two ways:
Give the path to scp:
ls -1 /dev/shm/split/1/ | sed -n '21443,42806p' | xargs -i \
scp -i ~/emails/name.pem /dev/shm/split/1/{} root#ipaddress:/dev/shm/split/2/
Change to that directory and it will work:
cd /dev/shm/split/1/; ls -1 | sed -n '21443,42806p' | xargs -i \
scp -i ~/emails/name.pem {} root#ipaddress:/dev/shm/split/2/

Changing the permission so the directory is world writable on CentOS 7

I've installed Xenforo on my digitalocean VPS running CentOS 7, I get this error as soon as I open the web page. `The following errors occurred while verifying that your server can run XenForo:
The directory /var/www/html/data must be writable. Please change the permissions on this directory to be world writable (chmod 0777). If the directory does not exist, please create it.
The directory /var/www/html/internal_data must be writable. Please change the permissions on this directory to be world writable (chmod 0777). If the directory does not exist, please create it.
Please correct these errors and try again.
How would I change the permission for the directory so it can be world writable?
Basically data and internal_data are directories in which the user running Xenforo should be able to write, because they will contain attachments, avatar, and other files.
Usually the user running PHP on Apache or Nginx is www-data in the group www-data (user and group have the same name), so all you have to do is letting this user to write on data and internal_data:
chown -R www-data.www-data /var/www/html/data /var/www/html/internal_data
If you want to follow literally the advice given in the error message you can do this instead:
chmod -R 0777 /var/www/html/data /var/www/html/internal_data
But as others commented, this approach is more insecure, because it will permit any user in the system to write in data and internal_data directories.
This is what is recommended for Xenforo 2 on nginx on CentOS per CentMinMod & Xenforo documentation. It is required to do it like this or Xenforo2 will not work. I have used this on multiple sites without issue. Make a backup first to be safe.
find /home/nginx/domains/domain.com/public/ -type f -print0 | xargs -0 chmod 0644;
find /home/nginx/domains/domain.com/public/ -type d -print0 | xargs -0 chmod 0755;
find /home/nginx/domains/domain.com/public/internal_data/ -type f -print0 | xargs -0 chmod 0777;
find /home/nginx/domains/domain.com/public/data/ -type f -print0 | xargs -0 chmod 0777;
find /home/nginx/domains/domain.com/public/internal_data/ -type d -print0 | xargs -0 chmod 0777;
find /home/nginx/domains/domain.com/public/data/ -type d -print0 | xargs -0 chmod 0777;
chmod 0750 /home/nginx/domains/domain.com/public;

permission in var/www on ubuntu

I was able to access and view the files when i first set it. i then realize that my css sheet was not running so i check the source code in Firefox and realize that i didn't have permission to view this file. so i decided to run a permission on the entire www folder.
Now im getting a 403 error. i tried changing back the permission but still having the same problem. i tried
find /var/www/ -type d -exec chmod 755 {} \;
find /var/www/ -type f -exec chmod 644 {} \;
these didn't work, please help
sudo chmod 0777 -R /var/www
-R is recursive, I assume that your web files are located in /var/www.