Solved

Usermode,Chmod,chgrp,chown

Posted on 2014-02-13
9
1,595 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 21

Assisted Solution

by:Mazdajai
Mazdajai earned 84 total points
ID: 39858089
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
ID: 39858174
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
ID: 39858186
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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
LVL 13

Assisted Solution

by:Sandy
Sandy earned 83 total points
ID: 39858255
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
 
LVL 5

Assisted Solution

by:Dave Gould
Dave Gould earned 167 total points
ID: 39858387
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
ID: 39859416
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
ID: 39860451
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
ID: 39861379
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
ID: 39863899
Thank you Guys!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

617 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