Operating System - HP-UX
1748021 Members
4616 Online
108757 Solutions
New Discussion юеВ

permission with chomd $ chown

 
madhudeepan
Frequent Advisor

permission with chomd $ chown

$id

uid=1001(test1) gid=1(other)
$ ls -al /etc/data

-r-------- 1 root other 394 jan 25 18:28 /etc/data

$ cat /etc/data

cat:cannot open /etc/data

what all options i have to enable both root and test1 to read /etc/data
9 REPLIES 9
Pete Randall
Outstanding Contributor

Re: permission with chomd $ chown

chmod g+r would do it.


Pete

Pete
Jitesh purohit_1
Regular Advisor

Re: permission with chomd $ chown

Hi Madhu

Currently only root has got the read permission, you can set chmod 444 if you want both test user also to have read permission

Thanks
Jitesh
Lijeesh N G_1
Respected Contributor

Re: permission with chomd $ chown

Hi,

Presently only owner can read the file;ie root and the permission is 400.

Change it it to 444;
#chmod 444 /etc/data
Verify with,
#ll /etc/data

Regards,
LIJEESH N G
SoorajCleris
Honored Contributor

Re: permission with chomd $ chown

Hi,

Changing it to 444 will meet the requirement. But please not that all others can also read /etc/data.

#chmod 444 /etc/data

If you want ONLY root and test1 wants to see this then you need to do something else

Regards,
Sooraj
"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity" - Dennis Ritchie
Matti_Kurkela
Honored Contributor

Re: permission with chomd $ chown

Root can *always* read & write everything, no matter what permissions are set.

chown test1 /etc/data
chmod 400 /etc/data

Result:
-r-------- 1 test1 other 394 jan 25 18:28 /etc/data

This would fulfill the requirement: test1 can read the file because he's the owner, and root can do anything with it because he's root.

Note that test1 can change the permissions of the file because he owns it.

------------

If the user test1 must not be able to change file permissions, then you must create a new group and to the group as its only member. (You don't need to change test1's primary group: the new group can be a secondary group)

# groupadd datagrp
# chown root:datagrp /etc/data
# chmod 640 /etc/data
# usermod -G datagrp test1

Result:
-rw-r----- 1 root datagrp 394 jan 25 18:28 /etc/data

$id
uid=1001(test1) gid=1(other) groups=NNN(datagrp)

Now test1 can read the file because of group membership, but cannot change its permissions because he isn't the owner of the file.

Root can still do anything: the rw permissions for root are just a reminder of this fact.

Advantages: if other users need to access /etc/data, just add them to the datagrp group. If test1 moves to other duties and will no longer need access to /etc/data, just remove the group membership.

MK
MK
V. Nyga
Honored Contributor

Re: permission with chomd $ chown

Amazing - why are some answers 'chmod 444 /etc/data' ?

This would give read permissions to all (world).
To change only for the group use the command from Pete or 'chmod 440 /etc/data'!

This would create:
-r--r----- 1 root other 394 jan 25 18:28 /etc/data

HTH
Volkmar
*** Say 'Thanks' with Kudos ***
Patrick Wallek
Honored Contributor

Re: permission with chomd $ chown

>>Amazing - why are some answers 'chmod 444 /etc/data' ?

Likely for the same reason some people just do 'chmod 777' to solve permission problems....
SoorajCleris
Honored Contributor

Re: permission with chomd $ chown

Exactly patrick!!! :)
"UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity" - Dennis Ritchie
V. Nyga
Honored Contributor

Re: permission with chomd $ chown

>#chmod 444 /etc/data

>If you want ONLY root and test1 wants to
>see this then you need to do something else

Should he beg then for what he 'need to do'?

V.
*** Say 'Thanks' with Kudos ***