Pular para o conteúdo principal

Linux 101: Using chmod and chown

Linux 101: Using chmod and chown: "

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.

Installation?

Not a bit. By default you will have both chmod and chown installed on your system.

Chmod

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:

  • r – 4
  • w – 2
  • x – 1

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:

774

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.

Chown

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

The above command would change both ownership and group ownership of the folder (since jacob.jacob was used). If you wanted to leave that folder belonging to the original group issue the command like:

sudo chown jacob /opt/APP

and the original group ownership would remain intact.

Final thoughts

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!


© Jack Wallen for gHacks Technology News, 2011. | Permalink | Add to del.icio.us, digg, facebook, reddit, twitter
Post tags: , , ,

"

Comentários

Postagens mais visitadas deste blog

Favigen, Favicon Generator

Favigen, Favicon Generator : " Favicons are small icons that help identify websites. They are used as a visual representation of a website both in the web browser and at many online services. The three most prominent locations of favicons are the browser’s address bar, the tabbar and the bookmarks folder. Many webmasters like to create custom favicons to add that custom identifier to their website. Favicons can be created in many image and icon editors, but also online. Favigen is a straightforward favicon generator that can turn an image into a favicon. All that it takes is to pick an image from the local hard drive first, select the dimensions of the favicon and click the submit button to make the service generate the favicon. Favigen supports several image formats, including jpg and png, and it does not seem to have size restrictions either. Available image dimensions range are 16×16, 32×32 and 64×64. The generated favicon is displayed directly on the page. A click on do...

A simple rsync script to back up your home directory

A simple rsync script to back up your home directory : " Backing up important data is obviously something we should all do. Unfortunately, it is not always easy to make it happen. We get lazy; we do not have the additional hardware for a backup server; it takes a long time and a lot of CDs to back up to optical media; we do not trust online backup services; backup schemes are difficult to set up and use — any of dozens of reasons can stand in our way. Still, we know we should be backing up our important data. Modern open source Unix-like operating systems offer a plethora of options for incredibly simple, effective backup schemes, however. If the problem is figuring out how to set one up, a simple rsync solution may be exactly what you need. The rsync utility is used to synchronize files between two systems. It does so by way of incremental copies, only copying from the source to the destination what has not already been copied there, saving time, network bandwidth, and syst...

The 10 hottest checklists, forms, and templates of 2010

The 10 hottest checklists, forms, and templates of 2010 : " The 10 hottest checklists, forms, and templates of 2010 Takeaway: TechRepublic published nearly 400 original downloads in 2010 — from cost calculators to cheat sheets to logs, templates, and PowerShell scripts. Here’s a rundown of some of the most popular items of the year. This year, we added hundreds of resources to the TechRepublic downloads library , including PDFs detailing the latest technologies, problem-solving techniques, and tips for handling tasks efficiently. We also updated a few favorite custom tools and introduced some new ones. Among the biggest crowd-pleasers were several checklists designed help you systematically address tasks ranging from server deployments to virus removal to project risk management. Here’s what you liked best in 2010. 1: Workstation Tune-up Checklist Optimizing a slow-performing system requires a number of diagnostic and repair steps, often with...