chmod vs chown


Results 1 to 10 of 10

Thread: chmod vs chown

  1. #1
    Join Date
    Apr 2004
    Location
    Christchurch, New Zealand
    Posts
    337

    chmod vs chown

    hey, what is the difference between chmod and chown, and which should I use and when?

    Thanks... -I am a little confused here
    "The religions disperse, kingdoms fall apart, but works of science remain for all ages."
    -- Ulugh-Beg

  2. #2
    Join Date
    Nov 2000
    Location
    Kongsberg, Norway
    Posts
    3,573
    It's obvious, isn't it?
    chown - Change ownership of file.
    chmod - Change modus of file. (read, write, execute)
    Linux User #181509

    * It can hardly be a coincidence that no language on this planet
    has ever come up with the phrase "as pretty as an airport" *
    -- Douglas Adams --

  3. #3
    Join Date
    Apr 2004
    Location
    Christchurch, New Zealand
    Posts
    337
    so if I was to make a folder as root say /downloads for example.. to use that under my user account I would need to
    chown -R :users /downloads
    and
    chmod -R 660 /downloads
    ??

    is this correct?

    thanks
    "The religions disperse, kingdoms fall apart, but works of science remain for all ages."
    -- Ulugh-Beg

  4. #4
    Join Date
    Aug 2000
    Location
    York, UK
    Posts
    117
    Essentially, if you want file my file.txt that belongs to user A to be fully accessible by another user B, there are two ways of doing it:

    1. chmod 777 file.txt makes the file completely open to anyone so obviously even user B (unsafe, not elegant)

    2. chown userB file.txt
    chgrp userB file.txt

    This changes the ownership fo the file and the group to which it belongs to userB (assuming that each user is in his/her own group). If all ordinary users are in the group "users", then change group ownership to that, from say, root's group.

    I hope this clears it, I suspect the confusion comes from people saying that if you want everyone to be able to access a file you should just chmod 777 it. I think that's confusing and inelegant but, hey I haven't got my head fully around permissions either and I've been using linux for almost 10 years now...
    Goldbach's conjecture: Every even number greater than 2 can be expressed as the sum of two primes.

  5. #5
    Join Date
    Aug 2000
    Location
    York, UK
    Posts
    117
    Sorry, I missed your reply earlier with the /download directory issue.

    This is a problem that I don't really have a clean solution for. The recommended way is to make a group (say downloads) and put all the users that want access to that directory in the group.

    But, if that directory is in a different filesystem (say another hard drive as on my system) it is still a problem because the directory will be mounted with root permission on bootup.

    A cheap solution is to add something along the lines:

    /dev/hda1 /download vfat uid=102, gid=102, users,auto,exec,dev

    to your fstab making sure you have the right filesystem and group id and so on. There is also a umask=*** option for fstab.

    But then you'll have another problem. Depending on what gui you have at bootup (I have gdm for example) the group owner of the mounted drives will become gdm instead of your download group.

    I still haven't found a clean solution but I'd welcome someone with more experience sending one.
    Goldbach's conjecture: Every even number greater than 2 can be expressed as the sum of two primes.

  6. #6
    Join Date
    Feb 2004
    Location
    The Matrix
    Posts
    466
    I have several distributions installed, by default I use Source Mage. I often want to have a look at stuff on my Gentoo partition, since that is the distribution I used to use and still has a lot of my personal stuff and configuration and stuff (though it's getting less by the day ). I mount Gentoo on /gen.
    Gentoo has exactly the same users as I have on Source Mage - after I've mounted my /gen partition, my SM user "sam" can freely access everything that used to be owned by my Gentoo user "sam" even though I haven't chrooted or whatever. I don't mount gentoo with anything special, only noatime (which doesn't have anything to do with this afaik).
    Thus, I think that if you make sure that all the files in /downloads are as you want them, owned by the right users and stuff, you can freely access it.
    This is just how it works for me - I'm not totally able to explain it, maybe something you can get some information out of it that works for you.
    Hope this helps
    Sam
    [EDIT] Wow! I just noticed that this is my 200th post! [/EDIT]
    [EDIT2]Ehhhmmm.... sorry - I just noticed that I didn't really answer your question: I think the commands are right, off course you don't need the -R if the dir's empty [/EDIT2]
    Last edited by Uranus; 07-02-2004 at 06:29 AM.
    I hated going to weddings. All the grandmas would poke me saying "You're next". They stopped that when I started doing it to them at funerals.
    OpenBox 3 | FVWM Crystal | FreeBSD | Linux Apps | Bash scripting | Perl | Python | My Site

  7. #7
    Join Date
    Apr 2004
    Location
    Christchurch, New Zealand
    Posts
    337
    Sorry, I missed your reply earlier with the /download directory issue.
    both posts at the same time, down to the minute ; )

    for vfat partitions i have to add them to the entire partition on mount. Is this a good idea to mount my reiserfs partitions in the same way with the uid=100 or whatever it is, or is it more 'elegant' as such to do so with chown?

    i think i understand now about chmod and chown
    thanks
    "The religions disperse, kingdoms fall apart, but works of science remain for all ages."
    -- Ulugh-Beg

  8. #8
    Join Date
    Apr 2004
    Location
    Christchurch, New Zealand
    Posts
    337
    john@odysseus john $ cd /files/
    -bash: cd: /files/: Permission denied
    john@odysseus john $ su
    Password:
    root@odysseus john # chown -Rv john: /files/
    changed ownership of `/files/' to john:users
    changed ownership of `/files/.reiserfs_priv' to john:users
    changed ownership of `/files/movies' to john:users
    changed ownership of `/files/movies/007' to john:users
    changed ownership of `/files/movies/007/01 - 1962 - Dr No.avi' to john:users
    changed ownership of `/files/movies/007/01 - Dr No - Part 1.avi' to john:users
    changed ownership of `/files/movies/007/01 - Dr No - Part 2.avi' to john:users
    changed ownership of `/files/movies/Hellraiser.avi' to john:users
    etc...
    root@odysseus john # chmod -Rv 660 /files/
    mode of `/files/' changed to 0660 (rw-rw----)
    mode of `/files/.reiserfs_priv' changed to 0660 (rw-rw----)
    mode of `/files/movies' changed to 0660 (rw-rw----)
    mode of `/files/movies/007' changed to 0660 (rw-rw----)
    mode of `/files/movies/007/01 - 1962 - Dr No.avi' changed to 0660 (rw-rw----)
    etc...
    root@odysseus john # exit
    john@odysseus john $ cd /files/
    -bash: cd: /files/: Permission denied
    john@odysseus john $
    it still isn't working.
    "The religions disperse, kingdoms fall apart, but works of science remain for all ages."
    -- Ulugh-Beg

  9. #9
    Join Date
    Nov 2000
    Location
    Kongsberg, Norway
    Posts
    3,573
    I believe you need execute permissions to 'cd' into those directories:

    # chmod -R 770 /files
    Linux User #181509

    * It can hardly be a coincidence that no language on this planet
    has ever come up with the phrase "as pretty as an airport" *
    -- Douglas Adams --

  10. #10
    Join Date
    Apr 2004
    Location
    Christchurch, New Zealand
    Posts
    337
    thank you that did the trick
    "The religions disperse, kingdoms fall apart, but works of science remain for all ages."
    -- Ulugh-Beg

Posting Permissions

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