Saturday, August 23, 2014

MAC permissions and editing


ls with -l option will give the list of files and  folders with their permissions 

ls -l 

as an example it gave the output like the below 

-rw-r--r--  1 root  admin  1941 Oct 10  2013 archive_sites.conf

The first letter here is - which indicates that it is a file. d would indicate it is a directory and l would indicate it as symbolic link

The next three characters specifies owner permissions

- indicates that no access, r indicates read access, w indicates write access, x indicates execute or folder browsing access

The next three letter set indicates group permissions. In this case, it is r-- which indicates that it is only read access. 

The last set indicates everyone else's permissions. again that is r-- indicates that is read only access to everyone else. 

The next element indicates the number of hard links for this file or folder in this case it is 1. 
Then given is the user name and followed by it, the group the user is assigned to. 

Followed by this there is a octal notation value for each entity (user, group and everyone else). 0 - means no access
1 indicates execution, 2 indicates write and 4 indicates read only. 

To change the ownership via command line, MAC terminal can use the chown command. 

The chown command works by accepting the username and group and then the items's path for e.g. like the below 

sudo chown myname:admin /opt/local/etc/macports/macports.conf 

To change the permissions via command line, chmod to be used. 

when using the chmod command, followed by the command, specify the account type (u for owner, g for group, and o for everyone), 
modifier (+ for adding, - for removing, = exact ) and the privilege 

for e.g. 

sudo chmod u=rwx /opt/local/etc/macports/macports.conf

the above command gave read, write and execute access to the macports.conf file 

the below command would give same level of permissions for all the users, e.g. owner, group and everyone 

sudo chmod ugo=rwx /opt/local/etc/macports/macports.conf

Please note that if some cases, we may need access  to the folders that leads to this file also to get full access to this in this case, we need to also do the below

sudo chmod ugo=rwx /opt/local/etc/macports

To recursively change the ownership of the file, below can be tried

sudo chown -Rv username directory

References:

No comments:

Post a Comment