I have run into a ton of file permission issues in Ubuntu, from not having permission to delete a file, change the contents of a while, and so on. I was wondering if some of you Ubuntu experts could share how you generally deal with file permission issues? What are some general guidelines and terminal commands to keep in mind?
Thanks in advance.
Every file on your system is owned by a user. Each user is a member of one or more groups. Using the
chmod
command a user can selectively allow self or others to read, write, or execute the file. Use ofchmod
is fairly complex, and you'll want to check outman chmod
before proceeding, or perhaps http://en.wikipedia.org/wiki/Chmod .Every file that I expect to need to edit is in my Home directory, and belongs to me. The only exception is the case of configuration files for system-wide things like Xorg or Samba. In general, new users probably shouldn't be editing these files by hand either, since other methods exist in most cases for adjusting those configurations.
After restoring backups, you'll find sometimes that you don't have permission to edit your own files. This is because, for example, you have reinstalled Ubuntu. Even though you set up a user with the same name during the reinstall and are logged in as that user, your UID is different, so the system regards you as a different user- not the one who owns the files. This is fixed by using the
chown
command. As withchmod
usage is complex, so read up on it first. Probably there is also a way to get Nautilus or some other command-line program to change file ownership also, but I don't know it.BE VERY CAREFUL when messing about with file ownership and permissions. You can cause great havoc this way.
Everything in @koanhead's answer is absolutely right. But what you seems to be asking for is an easy way to face file permissions issues, this is very simple.
If you are using terminal, you can:
man chmod
andman chown
in order to learn the appropiate usage of those commands. There are lots of stuff in the net, but you can be sure that the manuals in your system correspond to the command that you can use IN your system.
For a simple guide
You must have in consideration that you can change both file permissions and/or file owner by using both the commands I gave you above. The rules are simple:
chown will change the owner of a file/folder. A folder's owner can be changed even recursively (by adding the -R option). This way:
After which USERNAME will have full domain on ITEMNAME's contents (ITEMNAME can be a file or folder).
In order to do several tasks, and depending on the result that you expect. You can:
sudo chmod 777 ITEMNAME -R
in order to recursivelly allow everyone to perform any task over ITEMNAME, which can indeed be a file or folder. After that you can change the file/folder permissions in order to fit your needs.What I mean is that, if you wish to perform any task on your file/folder without restrictions, make it editable/writable/deletable for anyone (with 777 permissions) and go ahead. After that, make sure you restore the appropiate permissions to it.
Additional information on how to set proper permissions was dropped in a wiki link on @koanhead's answer.
Good luck!