Solved

Usermode,Chmod,chgrp,chown

Posted on 2014-02-13
9
1,536 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

752 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