10.10: chmod

Asked by peter

Who can give me a short summary about the chmod command? I read the man page, but it's quite a lot.

What does chmod +x 444 /etc/sudoers mean and what does chmod +x 777 mean?

I would be glad for every answer. Thanks a lot.
Peter

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu coreutils Edit question
Assignee:
No assignee Edit question
Solved by:
peter
Solved:
Last query:
Last reply:
Revision history for this message
mycae (mycae) said :
#1

type "man chmod" at a terminal.

Or online.
http://man.cx/chmod

Revision history for this message
mycae (mycae) said :
#2

Whoops.

Sorry

The 777 is the so-called octal represetnation The permissions come in 3 bits for user, group and world, which is equivalent to counting up to 8 in binary to enumerate all the possible combinations.

So if we make a table like:

 # R W X
 0 0 0 0
 1 0 0 1
 2 0 1 0
 3 0 1 1
4 1 0 0
5 1 0 1
6 1 1 0
7 1 1 1

this is the decoding for each octal value in the "777" So this would be Owner: 111 (rwx), Group 111 (rwx) and World 111 (rwx).

Revision history for this message
mycae (mycae) said :
#3

The other representation in your question (I really should read this more closely). Is the

chmod (u/g/a)(+/-)(r/w/x) FILENAME

so you can give user more permissions

chmod u+(r/w/x) FILENAME

or you can take them away

chmod u-(r/w/x) FILENAME

You can dot his for user (u), group(g) or all (a).

>chmod +x 444 /etc/sudoers mean

That seems a bit nonsense to me -- you should use the letter representation OR the octal represetnation, but nto both. Also, setting execute permissions on the sudoers file would be a bit daft, as it is not a script that is meant to be interpreted per se.

Revision history for this message
peter (peter-neuweiler) said :
#4

And in the table R means Read, W means Write and X means Execute? Thanks a lot.
Peter

Revision history for this message
peter (peter-neuweiler) said :
#5

But in the second example: chmod u+(r/w/x) FILENAME.

Do I have to write it like this? With r/w/x? Thanks.
Peter

Revision history for this message
David Mawdsley (dm-madmod) said :
#6

Lets suppose you create the following script using gedit:

#!/bin/bash
ls -l t* # List all the files in the current directory starting with 't'

and you save this two-line script as 'myscript' in your home directory.

Now in terminal type:
ls -l my* and then view the permissions on the left. You should see read and write privileges for the owner but not execute, and read privileges for the group and other. The octal of that should be 644. 644 in binary is 110 100 100. (6: 110 showing read, write; 4: 100 showing read) The '1' means permission granted, '0' means denied in the respective categories for owner, group and other.

Since 'myscript' needs to be executable use the following:
chmod u+x myscript to add the executables permission to the script for the user.
Now when you type:
ls -l my* and view the permissions you should see read, write, execute for the owner and the rest left as read only.
The octal of the permissions should now be 744 744 in binary is 111 100 100. (7: 111 showing read, write, execute; 4: 100 showing read only.)

Test it in terminal with
./myscript

The script should now run and do what it's meant to do.

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#7

If you change the ownership and access of the sudoers file you will BREAK your OS.

If you want to edit it simply run:

export EDITOR=nano; sudo -E visudo

Thats all you need, why are you messing with the ownership?

Revision history for this message
peter (peter-neuweiler) said :
#8

Joomla has a problem with the ownership. Thanks a lot.
Peter

Revision history for this message
peter (peter-neuweiler) said :
#9

And in the table R means Read, W means Write and X means Execute? Thanks a lot.

But in the second example: chmod u+(r/w/x) FILENAME.
Do I have to write it like this? With r/w/x? Thanks.
Peter

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#10

Boot to root recovery mode and run:

chown root:root /etc/sudoers; chmod 440 /etc/sudoers

My vanilla file reads like this:

andy@D420:~$ ls -l /etc/sudoers
-r--r----- 1 root root 609 2011-01-14 17:35 /etc/sudoers

HTH

Revision history for this message
peter (peter-neuweiler) said :
#11

solved. thanks.

Revision history for this message
Ralph Corderoy (ralph-inputplus) said :
#12

You really should ensure /etc/sudoers permissions are as actionparsnip said above; -r--r-----, owner root, group root. Anything else and it suggests something odd about your system and its security.

http://en.wikipedia.org/wiki/Chmod may give an introduction to chmod(1) that you're more happy with.

Revision history for this message
peter (peter-neuweiler) said :
#13

It's ok.

peter@peter:~$ ls -l /etc/sudoers
-r--r----- 1 root root 567 2010-12-21 19:46 /etc/sudoers

Thanks.
Peter

Revision history for this message
actionparsnip (andrew-woodhead666) said :
#14

FYI. I have used Ubuntu since Gutsy (7.10) and Linux since September 2000 and have NEVER had to mess with the sudoers file.