You can share access to your Linux files with other Linux users. You can grant “read” and/or “execute” access to everybody, or you can grant “read”, “write” and/or “execute” access to a group of users.
To share a file with everybody, you grant read access to the file and its directory. To make the file readable (but not writable) by everybody, enter:
chmod 644 filename
or chmod 755 filename if it is executable.
The chmod command is explained below. To make the current directory accessible, enter:
chmod 755 .
The period is the current directory. If the file is in a subdirectory, all of the directories involved must be accessible. Shift to each of the parent directories using:
cd ..
and repeat the chmod command until you get to your login directory.
The person who wants to access the file can use:
~your_name
to refer to your login directory. For example, if the file were in your login directory, that person could copy the file to a file by the same name in his or her current directory by entering:
cp ~yourname/filename .
The ls -l Command
To see the access permissions for a file, enter:
ls -l filename
The response is something like:
-rw-r--r-- 1 yourname group 4779 Jun 28 10:56 filename
The meaning of this output line is:
the - would be x if file were executable
To delete a file, a person must have write access to its directory. For a directory, a person must have execute access to use anything in the directory, read access to list the contents of the directory with an ls command, and write access to add or delete files in the directory.
chmod stands for “change mode”. The three-digit number after chmod controls the file's access permissions. The first digit controls the access for you (you could remove your own write access to avoid accidentally changing a file); the second digit controls the access for a group of users (how to set up a group is explain later); the third digit controls the access for everyone else. Each access type is assigned a number:
The value of a digit is the sum of the numbers for the accesses you are granting.
To set up a group, you must do the following:
To send e-mail to a group, mail to:
group/group-name@cae.wisc.edu
Note: Everyone in the group must have a Unix account at CAE.
To make a file accessible to a group that is not your default group, you must change the file's group assignment. chgrp stands for “change group”. The form of the command is:
chgrp groupname filename
To change the group for all the files in a directory (including subdirectories), enter:
chgrp -R groupname directoryname
To ensure that the group owns all new files and subdirectories created within a directory, enter:
chmod g+s directoryname
To see the current group of a file, enter:
ls -lg filename
To change your current default group for the remainder of your session, enter:
newgrp groupname
To change your default group permanently, mail a message requesting the change to HelpDesk@cae.wisc.edu.
Note: you cannot change your default group by entering a newgrp command at the end of your .cshrc file. Each newgrp command starts a new subshell which in turn reruns .cshrc. Thus, a newgrp command in .cshrc results in an infinite loop.