Wednesday, July 20, 2011

How to assign a password to a group?


Let’s view the existing users and groups they belong to.
‘listusers’ display the existing users.

bash-3.00# listusers
castro
che
noaccess No Access User
nobody NFS Anonymous Access User
nobody4 SunOS 4.x NFS Anonymous Access User


“id –a” displays the user id and the groups, group id the user belong to.
bash-3.00# id -a castro
uid=101(castro) gid=101(solaris) groups=101(solaris)

bash-3.00# id -a che
uid=100(che) gid=100(unix) groups=100(unix)



From the above output, we found the user ‘che’ belong to the group ‘unix’ and the user ‘castro’ belongs to the group solaris.

User name -> Group name
Che -> unix
Castro -> solaris

Now we login as user ‘che’ create files, directories and view the permissions of those files & directories.


bash-3.00# su - che
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
$ pwd
/export/home/che
$ touch one two
$ mkdir three four
$ ls -l
total 12
drwxr-xr-x 2 che unix 512 Jul 19 14:33 four
-rw-r--r-- 1 che unix 136 Jul 6 12:15 local.cshrc
-rw-r--r-- 1 che unix 157 Jul 6 12:15 local.login
-rw-r--r-- 1 che unix 174 Jul 6 12:15 local.profile
-rw-r--r-- 1 che unix 0 Jul 19 14:33 one
drwxrwsrwx 7 che solaris 512 Jul 6 12:21 test
drwxr-xr-x 2 che unix 512 Jul 19 14:33 three
-rw-r--r-- 1 che unix 0 Jul 19 14:33 two



Now we login as user ‘castro’ create files, directories and view the permissions of those files & directories.


bash-3.00# su - castro
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
$ pwd
/export/home/castro
$ touch file1 file2
$ mkdir dir1 dir2
$ ls -l
total 10
drwxr-xr-x 2 castro solaris 512 Jul 19 14:34 dir1
drwxr-xr-x 2 castro solaris 512 Jul 19 14:34 dir2
-rw-r--r-- 1 castro solaris 0 Jul 19 14:34 file1
-rw-r--r-- 1 castro solaris 0 Jul 19 14:34 file2
-rw-r--r-- 1 castro solaris 136 Jul 6 12:15 local.cshrc
-rw-r--r-- 1 castro solaris 157 Jul 6 12:15 local.login
-rw-r--r-- 1 castro solaris 174 Jul 6 12:15 local.profile



Now as user ‘che’ let us try to append the file ‘/export/home/castro/file1’
bash-3.00# su - che
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
bash-3.00$ cat >> /export/home/castro/file1
bash: /export/home/castro/file1: Permission denied


But, the error was thrown, stating Permission denied.


Now, as user ‘castro’ let us change the permission of the file ‘file1’

bash-3.00# su - castro
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
$ chmod 774 file1
$ ls -l | grep file1
-rwxrwxr-- 1 castro solaris 0 Jul 19 14:34 file1



Now from the above output, we observe that the permission of the file1 is changed.
Now again as user ‘che’ let’s try updating the file ‘file1’.
bash-3.00# su - che
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
bash-3.00$ cat >> /export/home/castro/file1
bash: /export/home/castro/file1: Permission denied



Again the same error is thrown, since the user ‘che’ does not belong to the group ‘solaris’.
Hence we are left with the following option:
1. We can add the user to the group ‘soalris’.
2. We can provide complete permission 777 to the file ‘file1’.
3. Assign a password to a group, can share the same with the user ‘che’.
We choose the option 3.

Now let’s discuss the process of assigning password to a group.

bash-3.00# grep solaris /etc/group
solaris::101:


From the above output we found, no password is assigned to the group

We don’t have any command to assign a password to a group.
Hence,
1. We assign a password to a user.
2. Copy the encrypted password from the file /etc/shadow
3. Copy the same to the second file of the file /etc/group against the group ‘solaris’ and save.

bash-3.00# passwd che
New Password:
Re-enter new Password:
passwd: password successfully changed for che
bash-3.00# grep che /etc/shadow
che:D2pXcjc4IYtbg:15174::::::


Now copy the encrypted password of the user ‘che’ and paste the same to the second filed of the file /etc/group against the group ‘solaris’ and save.

bash-3.00# vi /etc/group
root::0:
other::1:root
bin::2:root,daemon
sys::3:root,bin,adm
adm::4:root,daemon
uucp::5:root
mail::6:root
tty::7:root,adm
lp::8:root,adm
nuucp::9:root
staff::10:
daemon::12:root
sysadmin::14:
smmsp::25:
gdm::50:
webservd::80:
postgres::90:
nobody::60001:
noaccess::60002:
nogroup::65534:
unix::100:
solaris: D2pXcjc4IYtbg:101::10:
:wq!
bash-3.00# grep solaris /etc/group
solaris:D2pXcjc4IYtbg:101:



Now as user ‘che’, we try login to the group ‘solaris’
‘newgrp” fulfill our need.
Whilst executing the command, it prompts for the password, now issue the password and try updating the file ‘file1’.

bash-3.00# su - che
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
bash-3.00$ newgrp solaris
newgrp: Password:
$ cat >> /export/home/castro/file1
welcome to the world of unix
have a great day
It work's
$


Now no error is thrown.

Let’s check whether the file is updated from the user ‘castro’ login –
bash-3.00# su - castro
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
$ cat file1
welcome to the world of unix
have a great day
It work's
$


The file is updated.



NOTE:

Where in Linux, we are provided with the command ‘gpasswd’ to assign password to a group.
[root@redhat5vm1 ~]# uname -a
Linux redhat5vm1 2.6.18-8.el5 #1 SMP Fri Jan 26 14:15:21 EST 2007 i686 i686 i386 GNU/Linux
[root@redhat5vm1 ~]# gpasswd solaris
Changing the password for group solaris
New Password:
Re-enter new password:

1 comment: