Usermode,Chmod,chgrp,chown

I would like to understand how the following commands are used and in which case each command is used.

Usermode
Chmod
chgrp
chown

Thank you
jskfanAsked:
Who is Participating?
 
Dave GouldOnsite SupportCommented:
When you see the line
-rwxrwxrwx 1 dave mygroup 0 Feb 14 09:03 test
you need to know hoz to break down the -rwxrwxrwx and this is really not so complicated.

the first char (th hyphen) is reserved for special purposes such as indicating that the object is a directory (d)
The next three characters indicate what rights the owner (in this case dave) has on the fichier. In the above example dave can read, write, and execute the file.

the next three characters indicate what right the members of the group "mygroup" have on the file. In the example above, they also have read, write and execute.

the last three characters indicate what rights anybody else (ie neither dave nor members of the group mygroup) have on the file.

So if you want to change the rights of dave, mygroup or others, you use the chmod command.
If you want to make ozo the owner of the file instead of dave, you use the chown command (chown ozo test)
If you want to give members of the group "yourgroup" the special rights that mygroup have at the moment, you replace mygroup with yourgroup using the chgrp command (chgrp yourgroup test)

As for the usermod command, it has no direct influence on the file rights and should not be considered in your command comparisons here. Look at the attributes that you have by checking your login in the file /etc/passwd. You can change any of these attributes with the usermod command. ie change your comment, homedir, default shell, group....)

Hope tis helps clear things up a little
0
 
MazdajaiCommented:
Have you look at the man page?

usermod - modify a user account
chmod - change file permission / mode bits
chgrp - change group ownership
chown - change file owner and group

man usermod
man chmod
man chgrp
man chown

Open in new window

0
 
jskfanAuthor Commented:
Can you please provide some examples , that will show the difference between each command as well the usage of it…

I read online about each command on :http://www.computerhope.com/unix

but not really enough. the way you explained them, looks good it can be better if you add examples for each command.

usermod - modify a user account
example:
chmod - change file permission / mode bits
example:
chgrp - change group ownership
example:
chown - change file owner and group
example:

Thank you
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
ozoCommented:
There are examples in the man pages, as well as at the online link you referenced.
If you you did not understand those examples, perhaps you can tell us what you found unclear so we can try to explain.
Or perhaps you can tell us a task you want to perform, and we can help you construct a command to do that.
0
 
SandyCommented:
usermod - modify a user account
example: #usermod -c "Printer Admin" admin1
chmod - change file permission / mode bits
example: #chmod 777 /tmp/myfile
chgrp - change group ownership
example: #chgrp staff /tmp/myfile
chown - change file owner and group
example: #chown admin1 /tmp/myfile

TY/SA
0
 
Dave GouldOnsite SupportCommented:
Do you know the useradd command ? Well user mod is like useradd but simply used to modify the attributes of an existing user.

chmod - look at this example:
$ ls -l test
 -rw-r--r-- 1 dave mygroup 0 Feb 14 09:03 test
$ chmod 777 test                   (give everybody read/write/execute)
$ ls -l test
-rwxrwxrwx 1 dave mygroup 0 Feb 14 09:03 test
$ chmod o-wx test                 (another way of changing - remove write/execute for "others")
-bash-3.2$ ls -l test
-rwxrwxr-- 1 dave mygroup 0 Feb 14 09:03 test

You can see that the perimissions are modified using chmod

Now change the group for the file test (the group "anygroup" must exist):
$ chgrp anygroup test
$ ls -l test
-rwxrwxr-- 1 zt910705 anygroup 0 Feb 14 09:03 test

Now change the owner of the file test (user "another_user" must exist):
$ chown another_user test
$ ls -l test
-rwxrwxr-- 1 another_user anygroup 0 Feb 14 09:03 test
0
 
jskfanAuthor Commented:
Correct me if I am wrong

So when you want to  give ownership of a file or a folder to a Group you  use Chgrp.
Example: Chgrp GroupX /Xfolder : GroupX will have folder ownership of Xfolder
Or Chgrp GroupX /Xfolder/Xfile  : GroupX will have only File ownership of Xfile without giving the group GroupX ownership of Xfolder.

Chown , seems like it does the same thing as Chgrp, but it is used to give permission to a user instead of a group

those 4 commands , they looks like they overlap in their usage, that s what confuses me
0
 
ozoCommented:
Essentially correct.
Is your confusion about the distinction between group and owner permission?
your
 rw-r--r-- 1 dave mygroup
from  ls -l test shows read, write, and execute permissions for the owner (rw-).
for members of the group (r--),
and for others (r--)
chown changes who (dave) the owner permissions apply to
chgrp changes who (mygroup) the group permissions apply to
0
 
jskfanAuthor Commented:
Thank you Guys!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.