When you use Linux
long enough you are going to use the command line. Although nearly every command line trick can be done from a GUI front end now, there are times when the command line is the only route (headless server for example). When you have to go that route, you will be glad to have the fundamentals of the more important Linux commands under your belt. Two very important commands, chmod and chown, deal with permissions and ownership (respectively). With these tools you control who owns and who reads, writes, and executes files and folders on your linux system . Let’s take a look at how to use these commands.
Not a bit. By default you will have both chmod and chown installed on your system.
The chmod command allows you to change permissions on a file. The basic usage is:
chmod PERMISSIONS FILE
Where PERMISSIONS is either the numeric or the alpha equivalent of the permissions you want to assign and FILE is the file (or folder) you want to effect.
Since the numeric permissions are the easiest to understand (and use) let’s look at that method.
Remember, file permissions are in the form:
OWNER | GROUP | All Others
Each of those sections includes:
READ | WRITE | EXECUTE
Each permission (read, write, execute) is represented with the binary representation of the initial letter:
To get the numeric permission you add which permissions you want to use together. So if you want r+w you get 6. If you want r+w+x you get 7. If you want r+x you get 5. If you want only r you get 4. So now, remembering you have to cover permissions for three different users (Owner, Group, All Others), you will need to have a numeric number for each. So if you want Owner and Group to have rwx permission and All Others to only have r permissions, you would have:
Now, to change the permission of a particular file to 774 you would issue the command:
chmod 774 FILENAME
Where FILENAME is the name of the file.
Now let’s examine the changing of ownership. This will bite you when you install an application in a directory as one user and need to use it as another. So let’s say you have a folder in the /opt directory called APP that belongs to user bethany but user jacob needs to own it instead (of course if they both need access you could just change permissions or create a group for this). To change the ownership of this folder (you will need administrative rights to do this) you would issue a command like:
sudo chown jacob.jacob /opt/APP
sudo chown jacob /opt/APP
and the original group ownership would remain intact.
Permissions and ownership on Linux isn’t nearly as challenging as you though – even from the command line! Of course you can do these same tasks from within your file manage – if you have a file manager!