user3213561
user3213561

Reputation: 369

Changing File Permissions Linux

It looks like I can't write to this file because of the file permission

Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/
root)

How do I change the file permission so I can write to it?

Upvotes: 6

Views: 24124

Answers (7)

Siva Prakash S
Siva Prakash S

Reputation: 1

You can change the permission of a folder alone using

chmod 777 folder-name

If you want its subdirectories permissions also changed, use

chmod -R folder-name

** Note: chmod 777 gives all access to the folder and its files

Upvotes: 0

avinash kumar
avinash kumar

Reputation: 51

sudo chmod a+rwx path work for me

Upvotes: 0

Stefan x
Stefan x

Reputation: 21

Old post, but maybe somebody will still find useful my answer.

If you want to give access to all users (or "other than owner" - meaning last digit ) you can run next command:

 cd <path where you want to apply your changes>
 sudo find . -perm 750  -exec chmod 757 {} +;

It will find all files with permission 750 (read + write + execute for owner user / read + execute for group owner / nothing for other users) and by changing just last digit, you give the same permission as owner, to all other users. (last 7 meaning read + write + execute for other users)

Of course, you can run the command with different digits, but just replace last digit with the value of first on. For example, run next commands to ensure that all file that are read + write + executable for owner, will have the same right access for 'other':

sudo find . -perm 700  -exec chmod 707 {} +;
sudo find . -perm 701  -exec chmod 707 {} +;
sudo find . -perm 702  -exec chmod 707 {} +;
sudo find . -perm 703  -exec chmod 707 {} +;
sudo find . -perm 704  -exec chmod 707 {} +;
sudo find . -perm 705  -exec chmod 707 {} +;
sudo find . -perm 706  -exec chmod 707 {} +;

If you will continue in this way (having one line for every combination 7xx), you will end up running 77 commands. Which is a bit too much... right?

Luckily, there can be done a trick. You can use "-" in front of the number that meaning that the file has "at least" that number. For example, running:

sudo find . -perm -775 

will return all files that have permission 775, 776 and 777. Another example is running:

sudo find . -perm -770 

that will return files with permision 770, 771 ... 777.

In our case, we are care only about first digit and we want to change last digit with its value, so there can used:

sudo find . -perm 700  -exec chmod 777 {} +;

**> This will work only for files on which owner has read + write +

execute. If you will try above command with 600 instead of 700, keep in mind that it will return also files with permission 6xx and files with permission 7xx.**

Upvotes: 0

user4825254
user4825254

Reputation:

chmod

The chmod command is used to change the permissions of a file or directory. To use it, you specify the desired permission settings and the file or files that you wish to modify. There are two ways to specify the permissions, but I am only going to teach one way.

It is easy to think of the permission settings as a series of bits (which is how the computer thinks about them). Here's how it works:

rwx rwx rwx = 111 111 111

rw- rw- rw- = 110 110 110

rwx --- --- = 111 000 000

and so on...

rwx = 111 in binary = 7

rw- = 110 in binary = 6

r-x = 101 in binary = 5

r-- = 100 in binary = 4

777

(rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.

755

(rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.

700

(rwx------) The file's owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.

666

(rw-rw-rw-) All users may read and write the file.

644

(rw-r--r--) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.

600

(rw-------) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.

Directory permissions

The chmod command can also be used to control the access permissions for directories. In most ways, the permissions scheme for directories works the same way as they do with files. However, the execution permission is used in a different way. It provides control for access to file listing and other things. Here are some useful settings for directories:

777

(rwxrwxrwx) No restrictions on permissions. Anybody may list files, create new files in the directory and delete files in the directory. Generally not a good setting.

755

(rwxr-xr-x) The directory owner has full access. All others may list the directory, but cannot create files nor delete them. This setting is common for directories that you wish to share with other users.

700

(rwx------) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.

Upvotes: 12

Eric Renouf
Eric Renouf

Reputation: 14520

To change the owner of the file use chown as in

chown <new user>[.<new group>] <file>

Upvotes: 0

Surajeet Bharati
Surajeet Bharati

Reputation: 1433

Use this command on terminal

sudo chmod 777 fileName

to grant all access (Read, Write, Execute).

If you don't need execution access and need only right access then

sudo chmod 666 fileName

In general, chmod commands take the form:

chmod options permissions filename

If no options are specified, chmod modifies the permissions of the file specified by filename to the permissions specified by permissions.

permissions defines the permissions for the owner of the file (the user), members of the group who owns the file (the group), and anyone else (others). There are two ways to represent these permissions: with symbols (alphanumeric characters), or with octal numbers (the digits 0 through 7).

Example

chmod 754 myfile

Here the digits 7, 5, and 4 each individually represent the permissions for the user, group, and others, in that order. Each digit is a combination of the numbers 4, 2, 1, and 0:

  • 4 stands for "read",
  • 2 stands for "write",
  • 1 stands for "execute", and
  • 0 stands for "no permission."

So 7 is the combination of permissions 4+2+1 (read, write, and execute), 5 is 4+0+1 (read, no write, and execute), and 4 is 4+0+0 (read, no write, and no execute).

enter image description here

I think, you got the idea. For more detail read man entry of chmod (this page).

Upvotes: 4

Arnab Nandy
Arnab Nandy

Reputation: 6712

Use chmod command, as a example ;

chmod 755 filename

Upvotes: 0

Related Questions