Linux set permission to all files

Chmod 777 to a folder and all contents [duplicate]

I have a web directory /www and a folder in that directory called store . Within store are several files and folders. I want to give the folder store and all files and folders within the store folder all permissions. How do I do this? I am guessing via .htaccess.

You need to seriously think about giving 777 to all files and folders under /www directory, which means all your files and directories will be readable, writable and executable by whole world.

Just to counter the alarmist misinformation in the comments: your files probably won’t be writeable or even likely readable «by the whole world». You’d have to setup a web server that explicitly allowed these things, which would be very uncommon. These files will be readable, writeable, and executable by any user who’s able to login to your system.

@JoshNoe It isn’t alarmist. Read the OWASP top 10 web application security vulnerabilities: A5 is «security misconfiguration» (e.g. 777 on upload directory) and A1 is «injection». A1 + A5 = pwnd. google.com/search?q=nginx+config+php+code+injection+jpg+comment On Linux the web server runs under a user (e.g. www-data) so every time the server serves a file it is a user logged into the system.

@Pocketsand Granting 777 to the user your web server runs under generally won’t open your files to «the whole world». By default, most web servers don’y serve any files by default, until you explicitly set them up to.

@JoshNoe I assume you’re talking about whether directory listings are configured but that is not what is being discussed here. The comments are concerning basic defensive security principles to help prevent things like code injection and directory traversal attacks. What your saying is analogous to «It’s alarmist to say people should lock their doors if their curtains are already shut.»

7 Answers 7

If you are going for a console command it would be:

chmod -R 777 /www/store . The -R (or —recursive ) options make it recursive.

Or if you want to make all the files in the current directory have all permissions type:

If you need more info about chmod command see: File permission

and if you have a symlink to said folder, to change the permissions on the symlink do chmod -h 777 /some_path/symlink

Note chmod -R 777 /some/path will fail silently if your target is a one of the following file systems: NFTS / exFAT / FAT32

If by all permissions you mean 777

You can give permission to folder and all its contents using option -R i.e Recursive permissions.

But I would suggest not to give 777 permission to all folder and it’s all contents. You should give specific permission to each sub-folder in www directory folders.

Читайте также:  Linux create delete file

Ideally, give 755 permission for security reasons to the web folder.

sudo chmod -R 755 /www/store 

Each number has meaning in permission. Do not give full permission.

N Description ls binary 0 No permissions at all --- 000 1 Only execute --x 001 2 Only write -w- 010 3 Write and execute -wx 011 4 Only read r-- 100 5 Read and execute r-x 101 6 Read and write rw- 110 7 Read, write, and execute rwx 111 
  • First Number 7 — Read, write, and execute for the user.
  • Second Number 5 — Read and execute for the group.
  • Third Number 5 — Read and execute for others.

If your production web folder has multiple users, then you can set permissions and user groups accordingly.

I haven’t downvoted, but I think the reason is that your answer does not cover the OPs question. It’s still a good answer, just not for this topic.

@MarijkeLuttekes: There are already answers who are giving light on how to give 777 permissions to folder. That’s not my intention to answer. I am saying not to give 777 permission to folder at all to www folder. See first comment for question of anubhava. Instead give 755 or required permissions. We understand sometimes from question that OP is heading in wrong direction. Then we should give path should be followed. It’s not only OP will be requiring solution. With same question another person will come to this page for finding answer, then that person will understand what this answer.

This should be marked the correct answer. While the other answers give the ‘solution’ to the problem, this one explains how a typical folder structure should be setup. Very rarely if ever would you want to make a web folder 777. Read the More info links that @SomnathMuluk has provided so that you can understand why.

Источник

File Permissions in Linux / Unix: How to Read, Write & Change?

Linux is a clone of UNIX, the multi-user operating system which can be accessed by many users simultaneously. Linux can also be used in mainframes and servers without any modifications. But this raises security concerns as an unsolicited or malign user can corrupt, change or remove crucial data. For effective security, Linux divides authorization into 2 levels.

In this Linux file commands tutorial, you will learn-

The concept of Linux File permission and ownership is crucial in Linux. Here, we will explain Linux permissions and ownership and will discuss both of them. Let us start with the Ownership.

Click here if the video is not accessible

Linux File Ownership

Every file and directory on your Unix/Linux system is assigned 3 types of owner, given below.

User

A user is the owner of the file. By default, the person who created a file becomes its owner. Hence, a user is also sometimes called an owner.

Group

A user- group can contain multiple users. All users belonging to a group will have the same Linux group permissions access to the file. Suppose you have a project where a number of people require access to a file. Instead of manually assigning permissions to each user, you could add all users to a group, and assign group permission to file such that only this group members and no one else can read or modify the files.

Читайте также:  How install android sdk linux

Other

Any other user who has access to a file. This person has neither created the file, nor he belongs to a usergroup who could own the file. Practically, it means everybody else. Hence, when you set the permission for others, it is also referred as set permissions for the world.

Now, the big question arises how does Linux distinguish between these three user types so that a user ‘A’ cannot affect a file which contains some other user ‘B’s’ vital information/data. It is like you do not want your colleague, who works on your Linux computer, to view your images. This is where Permissions set in, and they define user behavior.

Let us understand the Permission system on Linux.

Linux File Permissions

Every file and directory in your UNIX/Linux system has following 3 permissions defined for all the 3 owners discussed above.

  • Read: This permission give you the authority to open and read a file. Read permission on a directory gives you the ability to lists its content.
  • Write: The write permission gives you the authority to modify the contents of a file. The write permission on a directory gives you the authority to add, remove and rename files stored in the directory. Consider a scenario where you have to write permission on file but do not have write permission on the directory where the file is stored. You will be able to modify the file contents. But you will not be able to rename, move or remove the file from the directory.
  • Execute: In Windows, an executable program usually has an extension “.exe” and which you can easily run. In Unix/Linux, you cannot run a program unless the execute permission is set. If the execute permission is not set, you might still be able to see/modify the program code(provided read & write permissions are set), but not run it.

File Permissions in Linux/Unix

Let’s see file permissions in Linux with examples:

ls – l on terminal gives

File Permissions in Linux/Unix

Here, we have highlighted ‘-rw-rw-r–‘and this weird looking code is the one that tells us about the Unix permissions given to the owner, user group and the world.

Here, the first ‘‘ implies that we have selected a file.p>

Else, if it were a directory, d would have been shown.

File Permissions in Linux/Unix

The characters are pretty easy to remember.

r = read permission
w = write permission
x = execute permission
= no permission

Let us look at it this way.

The first part of the code is ‘rw-‘. This suggests that the owner ‘Home’ can:

  • Read the file
  • Write or edit the file
  • He cannot execute the file since the execute bit is set to ‘-‘.

By design, many Linux distributions like Fedora, CentOS, Ubuntu, etc. will add users to a group of the same group name as the user name. Thus, a user ‘tom’ is added to a group named ‘tom’.

The second part is ‘rw-‘. It for the user group ‘Home’ and group-members can:

Читайте также:  Dr web linux демо

The third part is for the world which means any user. It says ‘r–‘. This means the user can only:

File Permissions in Linux/Unix

Changing file/directory permissions in Linux Using ‘chmod’ command

Say you do not want your colleague to see your personal images. This can be achieved by changing file permissions.

We can use the ‘chmod’ command which stands for ‘change mode’. Using the command, we can set permissions (read, write, execute) on a file/directory for the owner, group and the world.

chmod permissions filename

There are 2 ways to use the command –

Absolute(Numeric) Mode in Linux

In this mode, file permissions are not represented as characters but a three-digit octal number.

The table below gives numbers for all for permissions types.

Number Permission Type Symbol
0 No Permission
1 Execute –x
2 Write -w-
3 Execute + Write -wx
4 Read r–
5 Read + Execute r-x
6 Read +Write rw-
7 Read + Write +Execute rwx

Let’s see the chmod permissions command in action.

File Permissions in Linux/Unix

In the above-given terminal window, we have changed the permissions of the file ‘sample to ‘764’.

File Permissions in Linux/Unix

‘764’ absolute code says the following:

  • Owner can read, write and execute
  • Usergroup can read and write
  • World can only read

This is shown as ‘-rwxrw-r–

This is how you can change user permissions in Linux on file by assigning an absolute number.

Symbolic Mode in Linux

In the Absolute mode, you change permissions for all 3 owners. In the symbolic mode, you can modify permissions of a specific owner. It makes use of mathematical symbols to modify the Unix file permissions.

Operator Description
+ Adds a permission to a file or directory
Removes the permission
= Sets the permission and overrides the permissions set earlier.

The various owners are represented as –

User Denotations
u user/owner
g group
o other
a all

We will not be using permissions in numbers like 755 but characters like rwx. Let’s look into an example

File Permissions in Linux/Unix

Changing Ownership and Group in Linux

For changing the ownership of a file/directory, you can use the following command:

In case you want to change the user as well as group for a file or directory use the command

File Permissions in Linux/Unix

In case you want to change group-owner only, use the command

chgrp group_name filename

chgrp’ stands for change group.

File Permissions in Linux/Unix

Tip

  • The file /etc/group contains all the groups defined in the system
  • You can use the command “groups” to find all the groups you are a member of

File Permissions in Linux/Unix

File Permissions in Linux/Unix

Summary:

  • Linux being a multi-user system uses permissions and ownership for security.
  • There are three user types on a Linux system viz. User, Group and Other
  • Linux divides the file permissions into read, write and execute denoted by r,w, and x
  • The permissions on a file can be changed by ‘chmod’ command which can be further divided into Absolute and Symbolic mode
  • The ‘chown’ command can change the ownership of a file/directory. Use the following commands: chown user file or chown user:group file
  • The ‘chgrp’ command can change the group ownership chrgrp group filename
  • What does x – eXecuting a directory mean? A: Being allowed to “enter” a dir and gain possible access to sub-dirs.

Источник

Оцените статью
Adblock
detector