Questions tagged [chmod]

The `chmod` command is used to adjust file permissions to read, write and execute for the owner, group and others.

chmod is an abbreviation of change mode. A file's mode is the set of permissions attached to it that control access:

permissions

Permission settings have different effects on regular files and on directories:

files and directories compared

chmod can also set the special permissions setuid, setgid and sticky bit.

chmod commands may be given in symbolic notation:

u = file owner
g = file group owner
o = everyone else
a = all of the above

Examples:

chmod u+x        #give owner only execute permission
chmod o-w        #remove global write permission
chmod g=r        #set group permission to read only
chmod u+w,go=rx  #give owner write permission & set permissions for group and others to read & execute only
chmod g+s        #add the setgid bit

Octal notation may also be used. An absent digit will be interpreted as a leading zero, so chmod 1 file is the same as chmod 0001 file The last three digits refer to the three sections of the mode and act as follows:

1 = x only
2 = w only
3 = w and x
4 = r only
5 = r and x
6 = r and w
7 = r w and x

The first digit applies special permissions:

1 = sticky bit
2 = setgid
4 = setuid

Examples:

chmod 644   #owner may read and write, group & others only read
chmod 755   #owner may read write and execute, group & others read and execute
chmod 2750  #setgid, owner may read write and execute, group may read and execute, others have no permissions

The command takes multiple file names as arguments:

chmod 744 foo bar baz  #gives the owner rwx and all others r only on the files foo bar and baz

It also has a -R recursive flag, but it is unusual for files and directories to need the same permissions.

581 questions
166
votes
5 answers

'chmod u+x' versus 'chmod +x'

What is the difference between chmod u+x and just chmod +x? I have seen a ton of tutorials that say to use u+x to make scripts executable. However, omitting the u doesn't seem to have any effect.
Nathan Schwermann
  • 2,167
  • 3
  • 16
  • 21
163
votes
10 answers

How do I use 'chmod' on an NTFS (or FAT32) partition?

I have a script that I need to execute on an NTFS partition. The script's permission is set to 600. I attempted to modify the permissions by running chmod 755 script.sh, which doesn't report a failure or anything - but it also doesn't change the…
Nathan Osman
  • 31,915
  • 40
  • 179
  • 259
108
votes
6 answers

Use chown to set the ownership of all a folder's subfolders and files?

How can I use the chown command to change the ownership of all a folder's subfolders and files?
TellMeWhy
  • 17,124
  • 39
  • 95
  • 141
104
votes
7 answers

What is the difference between "chmod +x" and "chmod 755"?

When it comes to making a file executable what is the difference between chmod 755 and chmod +x and when would I use which? I so far have only used chmod +x and I just read something and it used chmod 755 and I could not tell whether or not it was…
Darth4212
  • 1,258
  • 2
  • 10
  • 14
91
votes
4 answers

WSL Ubuntu Distro | How to solve `Operation not permitted` on cloning repository

I am running Ubuntu 18.04, as a Subsystem for Windows. I have done this in mutliple PCs and never had this problem. I try to to git clone , and I get this: Cloning into ''... error: chmod on…
Dimitris Efst
  • 1,013
  • 1
  • 8
  • 9
90
votes
3 answers

What does "chmod +x " do and how do I use it?

I want to write the Ubuntu analogue of a "batch file" (a shell script). But I don't know how to use chmod +x filename command to make it so that the script can be run. Nor do I know where to use it.
user265696
  • 921
  • 1
  • 7
  • 3
87
votes
6 answers

How can I chmod 777 all subfolders of /var/www?

I’m running a webserver and FTP server, wherein /var/www is bound to /home/user/www. I set both directories to chmod 777 (which is fine since it’s for testing only). I can upload files into /home/user/www, but whenever I create a new directory, I…
user1645034
  • 1,039
  • 2
  • 10
  • 11
82
votes
2 answers

chmod files only in all subdirectories

Please someone assist me with chmod, I have the following file structure -dir1 --file1 --file2 --dir1a ---file1a1 ---file1a2 --dir1b ---file1b1 ---file1b2 How do I chmod 655 to all files under dir1 and all subdir? So all files will have 655…
netic
  • 923
  • 1
  • 7
  • 5
71
votes
12 answers

What if I accidentally run command "chmod -R" on system directories (/, /etc, ...)

I accidently ran sudo chmod 755 -R / instead of sudo chmod 755 -R ./ I stopped it after few seconds, but now there is some problems such as sudo: must be setuid root How can I revert permissions back?
fl00r
  • 1,383
  • 4
  • 13
  • 18
68
votes
5 answers

Changing permissions on serial port

I'm using the Arduino IDE in Ubuntu, and am having issues with the serial port. It has worked in the past, but for reasons that may be unnecesary, I felt the need to change the ownership of some of the files from root ownership to my users…
Terrik
  • 793
  • 1
  • 6
  • 8
67
votes
6 answers

What is the main difference between chmod and chown?

In some examples, I saw that some used chown instead of chmod. I do not know where to use chmod and chown. Please explain to me the difference between them, when and why I should use either.
55
votes
2 answers

How can I check the folder permissions in ubuntu server 12.04?

Right now, I know that I can change permissions for example with: sudo chmod 550 directory I wonder how I can check the actual folder permission.
Private
  • 3,884
  • 9
  • 34
  • 48
54
votes
4 answers

Why does chmod 777 -R / leave the system unusable?

I'm only granting permission to all to do anything but why does the system crash by giving permissions only? I'm only modifying the permission not changing the files.
Brij Raj Kishore
  • 2,088
  • 3
  • 13
  • 23
53
votes
2 answers

How do file permissions work?

Can you explain briefly the main concepts and command line tools used to manage file permissions?
guillermooo
  • 633
  • 1
  • 7
  • 7
47
votes
5 answers

default permissions for /var/www

I was trying to open a file and write to it with PHP at /var/wwwfolder but it wasn't working so I did sudo chmod 777 /var/www now I want to set the permissions for /var/www to the default. what are the default permissions for /var/www?
Hossein Hosseinvand
  • 1,126
  • 2
  • 12
  • 12
1
2 3
38 39