Solved

Usermode,Chmod,chgrp,chown

Posted on 2014-02-13
9
1,237 Views
Last Modified: 2014-02-16
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
0
Comment
Question by:jskfan
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 21

Assisted Solution

by:Mazdajai
Mazdajai earned 84 total points
Comment Utility
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
 

Author Comment

by:jskfan
Comment Utility
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
 
LVL 84

Assisted Solution

by:ozo
ozo earned 166 total points
Comment Utility
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
 
LVL 13

Assisted Solution

by:Sandy
Sandy earned 83 total points
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 5

Assisted Solution

by:Dave Gould
Dave Gould earned 167 total points
Comment Utility
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
 

Author Comment

by:jskfan
Comment Utility
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
 
LVL 84

Assisted Solution

by:ozo
ozo earned 166 total points
Comment Utility
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
 
LVL 5

Accepted Solution

by:
Dave Gould earned 167 total points
Comment Utility
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
 

Author Closing Comment

by:jskfan
Comment Utility
Thank you Guys!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

This document is written for Red Hat Enterprise Linux AS release 4 and ORACLE 10g.  Earlier releases can be installed using this document as well however there are some additional steps for packages to be installed see Metalink. Disclaimer: I hav…
You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now