I log in to Ubuntu with the username student.

There are some directories only the root user is allowed to access, for example /var/lib/mysql, (I know I can use sudo to access it but it is not what I want). If I want to get the access privilege on those directories with the student account, can I use the following command:


and after that, can I access that directory by using my own account? Am I right?

  • If I am right, then will root user lose the access privilege because I changed it to the student user?

  • If I am wrong, please tell me the right solution.


This directory is restricted to root access for a reason. It is usually a bad idea (and a great security risk) to modify this ownership.

Moreover, instead of modifying the ownership, you could think about modifying the permission on the directory. A user can access a directory if he or she has the right to execute (+x) it. If you're unfamiliar with Unix file permissions, I suggest you read a tutorial. (A quick Google search and I came up with this random tutorial).

Other things:

  • root will never loose any privilege. root can do anything.
  • Only root will be able to chown.

The right solution

Simple as it is, sudo is the way to go. Ubuntu developers know what they're doing. The sudo utility is given to make privilege escalation easy and safe. There is absolutely no reason why you would want to change any of this.

  • Hi, just to confirm that by using chown, student account then can get the access of the directory which used to be root privileged, and root won't loose the access privilege to that directory, right? I just wanna know the effect of chown, does not mean I will do stupid thing – Mellon Dec 1 '11 at 9:08
  • The way you worded your question gives us the impression that you're not familiar enough with Unix permissions. It's no coincidence that you got 2 answers linking to outside tutorials. I suggest you look it up. Believe me, read the tutorial :) – rahmu Dec 1 '11 at 9:18
  • thank you, I will read the tutorial, but can you still answer my question explicitly, if root user do chown a directory which used to be root privilege to the student account, will the student user then can access that directory without using sudo ? – Mellon Dec 1 '11 at 9:41
  • 2
    I already answered: It does not depend (directly) on the owner of the directory, but the access (+x) permission bits. Again, tutorial. You can't guess your way around Unix. At some point, you're going to have to learn it :) – rahmu Dec 1 '11 at 14:59

You should never change the ownership of files owned by root (or at least, almost never). Instead, you should use sudo to access root directories. root always has access to every file on the computer, whether they own it or not. Changing the directory to your own ownership breaks the GNU/Linux security model.


It all depends on the permissions that are set for the directory, you can do ls -l on the /var/lib/ directory in order to get the permissions for /var/lib/mysql .

You can read here about the permissions bits in Linux.

But to be specific to your question, if the permission bits are set correctly at the directory (which it should be by default) then the student user can access its own directory, and the root user wouldn't lose its privilege to access the directory. And you should run this command with sudo and probably with -R in order to change the ownership to all of the child directories.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.