Using Linux:Managing Users and Groups
-->
Previous
Table of Contents
Next
Managing Groups with gpasswd
To add users to an existing group, log in as the root user and enter the following command:
[root@insoc /root]# gpasswd -a loginname groupname
where loginname is the login name of the user you want to add to the group groupname.
For example, to add the user vector to the group ittf, you would use the command:
[root@insoc /root]# gpasswd -a vector ittf
To remove a user from an existing group, log in as the root user and enter the following command:
[root@insoc /root]# gpasswd -d loginname groupname
where loginname is the login that you want to remove from the group groupname.
For example, if you wanted to remove the user yoko from the group beatles, you would use the command:
[root@insoc /root]# gpasswd -d yoko beatles
For a full list of command-line options available for the gpasswd command, see the related man page.
Using the chgrp Command
To change the group of a file, use the chgrp command. Log in as the root user and enter the following command:
[root@insoc /root]# chgrp groupname filename
where groupname is the name of the group you want to change the files group setting to, and filename is the name of the file for which you want the group changed.
For example, if you wanted to change the group for the file index.html to www, you would use chgrp as follows:
[root@insoc /root]# chgrp www index.html
To change the group of a directory and all its subdirectories and files, you can use the chgrp command with the -R option. For example, to change the group on all the files in the htdocs directory to www, you would use:
[root@insoc /root]# chgrp -R www htdocs
Changing File Ownership and Permissions
Two programs in the command-line arsenal help change file ownership and permissions. chown, or Change Ownership, lets you change a file (or group of files) to another owner. chmod lets you change the access permissions to individual files.
Using the chown Command
To change the owner of a file, you use the chown command. Log in as the root user and enter the following command:
[root@insoc /root]# chown ownername filename
where ownername is the login name of the user you want to change the files owner setting to, and filename is the name of the file for which you want the owner changed.
For example, if you wanted to change the owner for the file index.html to sshah, you would use chown as follows:
[root@insoc /root]# chown sshah index.html
To change the owner of a directory and all its subdirectories and files, you can use the chown command with the -R option. For example, to change the owner on all the files in the htdocs directory to sshah, you would use:
[root@insoc /root]# chown -R sshah htdocs
Using the chmod Command
Before we can explain the usage of the chmod command, you need to first understand file permissions.
In Linux, every file and directory has three sets of access permissions: those applied to the owner of the file, those applied to the group the file has, and those of all users in the system. You can see these permissions when you do an ls -lg. For example:
drwxr-xr-x 2 sshah sysadmin 1024 Feb 14 15:49
wedding_plans
-rw------- 1 sshah sysadmin 2465 Feb 5 19:22
index.html
The first column of the listing is the permissions of the file. The first character represents the type of file (ëd means directory, ël means symbolic link, and so on), and the next nine characters are the permissions. The first three characters represent the permissions held by the files owner, the second three are for the group the file is in, and the last three represent the world permissions.
The following letters are used to represent permissions:
Letter
Meaning
r
Read
w
Write
x
Execute
Each permission has a corresponding value. The read attribute is equal to 4, the write attribute is equal to 2, and the execute attribute is equal to 1. When you combine attributes, you add their values. See the following examples.
The most common groups of three and their meanings are:
Permission
Values
Meaning
---
0
No permissions
r--
4
Read only
rw-
6
Read and write
rwx
7
Read, write, and execute
r-x
5
Read and execute
--x
1
Execute only
Although other combinations do exist (for example: -wx), they are nonsensical, and the likelihood youll ever run across them is almost nil.
Previous
Table of Contents
Next
Wyszukiwarka
Podobne podstrony:
420 422The Imaginarium of Doctor Parnassus 2009 DVDScr XviD 42001aff02a1cb3ae2b1d5a37b1d85453f7 zip (417 60 kB)420 (2)417 419420 (B2007) Rozliczenia międzyokresowe przychodów417 (B2007) Koszty na przełomie roku413 417Packard Bell ser 300,400,420417 acInstrukcjaGIWz 420 AW 46 10README (417)więcej podobnych podstron