As discussed above, any file that's newly created, the default value is 644 (rw-r--r--), meaning that the file's owner can read and write, and all others can only read this file.
Restore Default File Permissions Permissions of 644 mean that the owner of the file has read and write access, while the group members and other users on the system only have read access.
When you perform chmod 755 filename command you allow everyone to read and execute the file, the owner is allowed to write to the file as well. So, there should be no permission to everyone else other than the owner to write to the file, 755 permission is required.
chmod 400 myfile - Gives the user read permission, and removes all other permission. These permissions are specified in octal, the first char is for the user, second for the group and the third is for other.
Here's a summary that I have gathered
Explanations:
ls -l
) and everyone else (the public) are able to read the file, but not execute or write to it (permission number 4). There's also an interactive online calculator you can use to figure out what permissions to use: https://chmod-calculator.com/
They should be as restrictive as possible, but no more.
Usually 0644
is a good choice, which gives the owner read and write rights, but everybody else only read. 0755
for directories. But, it can depend on your specific system settings.
If you want to reset everything, do this command and sort out the consequences. Usually 644 is a good permission for files and 711 is for directories. If you allow directory listings, then use 755.
$ find /var/www/html \( -type f -execdir chmod 644 {} \; \) \
-o \( -type d -execdir chmod 711 {} \; \)
If you want something less invasive, then just remove the write bits for group and "other".
$ chmod -R go-w /var/www/html
I think 644
is standard for files and 755
for directories.
If your webserver serves only webpages, without allowing access through (e.g.) anonymous FTP, then incorrect file permissions do not allow users to remove files.
If other people have access to your server through other means (e.g. SSH), then make sure that the write-bit is not set for users other than yourself. Execute:
find . -exec chmod go-w {} \;
This command will restrict the permissions of all files and directories in which it is executed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With