Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: command: chmod

  1. #1
    Join Date
    Oct 2011
    Posts
    46
    Thanks
    0
    Thanked 7 Times in 6 Posts
    Rep Power
    10

    command: chmod

    chmod is a Linux command that will let you "set permissions" (aka, assign who can read/write/execute) on a file.

    Usage:
    Code:
     chmod permissions file
    OR:
    Usage:
    Code:
     chmod permission1_permission2_permission3 file
    When using chmod, you need to be aware that there are three types of Linux users that you are setting permissions for. Therefore, when setting permissions, you are assigning them for "yourself", "your group" and "everyone else" in the world. These users are technically know as:

    ● Owner
    ● Group
    ● World
    Therefore, when setting permissions on a file, you will want to assign all three levels of permissions, and not just one user.

    Think of the chmod command actually having the following syntax...
    chmod owner group world FileName
    Now that you understand that you are setting permissions for THREE user levels, you just have to wrap your head around what permissions you are able to set!

    There are three types of permissions that Linux allows for each file.

    ● read
    ● write
    ● execute
    Putting it all together:
    So, in laymen terms, if you wanted a file to be readable by everyone, and writable by only you, you would write the chmod command with the following structure.
    COMMAND : OWNER : GROUP : WORLD : PATH
    chmod read & write read read FileName
    chmod 6 4 4 myDoc.txt
    Wait! What are those numbers?!?
    Computers like numbers, not words. Sorry. You will have to deal with it. Take a look at the following output of `ls -l`
    Code:
    [root@demo]$ ls -l 
    -rw-r--r-- 1 gcawood iqnection 382 Dec 19 6:49 myDoc.txt
    You will need to convert the word read or write or execute into the numeric equivalent (octal) based on the table below.

    ● 4 – read (r)
    ● 2 – write (w)
    ● 1 – execute (x)
    Practical Examples

    chmod 400 mydoc.txt – read by owner
    chmod 040 mydoc.txt – read by group
    chmod 004 mydoc.txt – read by anybody (other)
    chmod 200 mydoc.txt – write by owner
    chmod 020 mydoc.txt – write by group
    chmod 002 mydoc.txt – write by anybody
    chmod 100 mydoc.txt – execute by owner
    chmod 010 mydoc.txt – execute by group
    chmod 001 mydoc.txt – execute by anybody
    Wait! I don't get it... there aren't enough permissions to do what I want!
    Good call. You need to add up the numbers to get other types of permissions...

    So, try wrapping your head around this!!
    7 = 4+2+1 (read/write/execute)
    6 = 4+2 (read/write)
    5 = 4+1 (read/execute)
    4 = 4 (read)
    3 = 2+1 (write/execute)
    2 = 2 (write)
    1 = 1 (execute)

    chmod 666 mydoc.txt – read/write by anybody! (the devil loves this one!)
    chmod 755 mydoc.txt – rwx for owner, rx for group and rx for the world
    chmod 777 mydoc.txt – read, write, execute for all! (may not be the best plan in the world...)
    Good luck! Hope this helps.
    (ps, never set things to 777 unless you have a really good reason to do so.)




  2. #2
    Join Date
    Nov 2011
    Location
    war driving
    Posts
    22
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    0
    very nice write up. It is also work noting that you can use shortcuts like the following
    chmod ug+rw file
    chmod o-r file
    chmod ugo=rwx file

  3. #3
    Join Date
    Nov 2011
    Posts
    93
    Thanks
    5
    Thanked 1 Time in 1 Post
    Rep Power
    2
    nice guide. thanks for reminding by the way.

    because every time i can't edit a file inside a directory, i just do chmod 777 * so i can edit files. the reason is that i don't exactly know which command to execute and its easier to me. but this is just something one would do if you know files aren't that important, the computer is yours and no one uses it except you.

  4. #4
    Join Date
    Nov 2011
    Posts
    88
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    2
    I've never CHMODD'ed via SSH..I always use the cPanel file manager (I have cPanel installed on my server). Guess it's important to know the 'get your hands dirty' method as well though.

    Thanks!

  5. #5
    Join Date
    Jan 2012
    Posts
    26
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    I don't usually CHMOD via SSH, unless there is a problem. I always use the cPanel file manager, or through an FTP client.

  6. #6
    Join Date
    Feb 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    ah this was one of the questions for my interview
    Thanks for this great post ... i`ll save it, because is very nicely explained

  7. #7
    Join Date
    Mar 2012
    Location
    Chongqing China
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    I have used it several times.It is very useful.

  8. #8
    Join Date
    Apr 2012
    Posts
    124
    Thanks
    5
    Thanked 1 Time in 1 Post
    Rep Power
    2
    Quote Originally Posted by mrnothersan View Post
    I don't usually CHMOD via SSH, unless there is a problem. I always use the cPanel file manager, or through an FTP client.
    This would be for doing things from scratch, it is handy to know for noobs. I tend to use my CHMOD via SSH so having a general path to follow is handy even if this is a quick rundown of how things work.

  9. #9
    Join Date
    Apr 2012
    Posts
    90
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    2
    Very nice tutorial! An example if you want to change the permissions of the file "participants" so that everybody has full access to it, you would enter:
    chmod 777 participants.

  10. #10
    Join Date
    Apr 2012
    Posts
    20
    Thanks
    1
    Thanked 1 Time in 1 Post
    Rep Power
    0
    chmod is a quite useful command, thanks for the description of chmod.

 

 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
           








Check out Linux Central for Linux software and other goodies!





» Stats

Members: 3,563
Threads: 3,917
Posts: 9,436
Top Poster: Fred (1,486)
Welcome to our newest member, nahidworld

» Links



Powered by vBadvanced CMPS