Questions tagged [chmod]

chmod is a linux/unix command. It stands for "change mode". This command is used change the permissions of directories and files.

chmod accepts either human readable notation of the octal bitwise mask. The bitwise mask often has the three digits, specifying (from left to right) permissions for the world, group and the owner of the file. The bits (left to right) are read, write, and execute. For instance,

chmod 740 x.sh

makes x.sh viewable, editable and executable for the current owner. The group can view but not change or execute, and the world has no access. This can be verified with ls -l x.sh:

-rw-r--r-- 1 me 11 2013-01-25 09:53 x.sh

Permission flags can also be specified as letters (r - read, w - write, x - execute), using + or - sign to turn them on or off, for all users. For instance

chmod +r-x x.sh

with make x.sh readable for possible users but no longer executable, even for the owner. The write permission that has not been mentioned in the command, will not be revoked form the owner:

-rw-r--r-- 1 me 11 2013-01-25 09:53 x.sh

Chmod also accepts the forth (actually first) digit that sets (left to right) setUID, setGUI and sticky flags. If not specified, it is assumed 0 (no such flags).

If chmod parameter is less than 3 digits, the first owner and then group permissions are assumed zero. The following example sets (probably in an unexpected way) full permissions for the world and no permissions for the user or group:

chmod 7 x.sh
cat x.sh
cat: x.sh: Permission denied
1322 questions
2815
votes
14 answers

How do I make Git ignore file mode (chmod) changes?

I have a project in which I have to change the mode of files with chmod to 777 while developing, but which should not change in the main repo. Git picks up on chmod -R 777 . and marks all files as changed. Is there a way to make Git ignore mode…
Ro Marcus Westin
  • 28,490
  • 4
  • 18
  • 11
2178
votes
19 answers

How do I change permissions for a folder and its subfolders/files?

How do I change the permissions of a folder and all its subfolders and files? This only applies to the /opt/lampp/htdocs folder, not its contents: chmod 775 /opt/lampp/htdocs How do I set chmod 755 for all of the /opt/lampp/htdocs folder's current…
Adam Halasz
  • 57,421
  • 66
  • 149
  • 213
714
votes
7 answers

Chmod 777 to a folder and all contents

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…
RSM
  • 14,540
  • 34
  • 97
  • 144
622
votes
7 answers

How to create file execute mode permissions in Git on Windows?

I use Git in Windows, and want to push the executable shell script into git repo by one commit. Usually I need to do two steps (git commit). $ vi install.sh $ git add install.sh $ git commit -am "add new file for installation" # first…
Larry Cai
  • 55,923
  • 34
  • 110
  • 156
399
votes
15 answers

Correct file permissions for WordPress

I've had a look over here but didn't find any details on the best file permissions. I also took a look at some of WordPress's form's questions over here too but anybody that suggests 777 obviously needs a little lesson in security. In short my…
John Crawford
  • 9,656
  • 9
  • 31
  • 42
253
votes
6 answers

Chmod recursively

I have an archive, which is archived by someone else, and I want to automatically, after I download it, to change a branch of the file system within the extracted files to gain read access. (I can't change how archive is created). I've looked into…
user797257
251
votes
14 answers

WARNING: UNPROTECTED PRIVATE KEY FILE! when trying to SSH into Amazon EC2 Instance

I'm working to set up Panda on an Amazon EC2 instance. I set up my account and tools last night and had no problem using SSH to interact with my own personal instance, but right now I'm not being allowed permission into Panda's EC2 instance. Getting…
btw
  • 7,006
  • 9
  • 40
  • 40
238
votes
7 answers

Change all files and folders permissions of a directory to 644/755

How would I change all files to 644 and all folders to 755 using chmod from the linux command prompt? (Terminal)
hugo der hungrige
  • 12,382
  • 9
  • 57
  • 84
172
votes
9 answers

How do you do a simple "chmod +x" from within python?

I want to create a file from within a python script that is executable. import os import stat os.chmod('somefile', stat.S_IEXEC) it appears os.chmod doesn't 'add' permissions the way unix chmod does. With the last line commented out, the file has…
priestc
  • 33,060
  • 24
  • 83
  • 117
146
votes
8 answers

How to create a directory and give permission in single command

How to create a directory and give permission in single command in Linux? I have to create lots of folder with full permission 777. Commands mkdir path/foldername chmod 777 path/foldername I don't like to create and give permission in two…
whiterose
  • 4,391
  • 8
  • 24
  • 18
142
votes
7 answers

Python module os.chmod(file, 664) does not change the permission to rw-rw-r-- but -w--wx----

Recently I am using Python module os, when I tried to change the permission of a file, I did not get the expected result. For example, I intended to change the permission to rw-rw-r--, os.chmod("/tmp/test_file", 664) The ownership permission is…
AplusG
  • 1,469
  • 2
  • 10
  • 9
117
votes
8 answers

Correct owner/group/permissions for Apache 2 site files/folders under Mac OS X?

It's hard to find Mac-specific answers to this question on the web, so I'm hoping someone out there can put this one to rest for me? My permissions are screwed up on my sites and I'm not sure how to fix them without just slamming a recursive 777 on…
Fo.
  • 3,752
  • 7
  • 28
  • 44
104
votes
3 answers

chmod WSL (Bash) doesn't work

Running bash on windows 10, the simple syntax below works when I SSH to my webserver, but not when I exit out and am on my local machine. It doesn't give me an error, but I can see permissions are unchanged. I have to checked that I am set up as an…
joe5
  • 1,101
  • 2
  • 8
  • 10
92
votes
3 answers

Difference between using "chmod a+x" and "chmod 755"

This may sound silly, but I have a file/ script that need to run and in order to do it I must change it to become executable. I would want to use either chmod a+x or chmod 755. But is there a difference between using chmod a+x and chmod 755?
user2579439
  • 1,193
  • 3
  • 13
  • 13
81
votes
12 answers

How do I give PHP write access to a directory?

I'm trying to use PHP to create a file, but it isn't working. I am assuming this is because it doesn't have write access (it's always been the problem before). I tried to test if this was the problem by making the folder chmod 0777, but that just…
Leagsaidh Gordon
  • 1,641
  • 5
  • 19
  • 28
1
2 3
88 89