Taking back ownership from root

Asked by Ron on 2011-05-13

How can I change ownership of my external hard drive? Right now, everything I have in my hd has to be modified only when I am signed in as root. How can I take back the ownership?

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu coreutils Edit question
Assignee:
No assignee Edit question
Solved by:
Eliah Kagan
Solved:
2011-05-13
Last query:
2011-05-13
Last reply:
2011-05-13
Ron (ronald17b95) said : #1

So I went to Terminal and typed in the following command:

chown -Rv [my username] /dev/sdc

The response I got from the system was:

changed ownership of `/dev/sdc' to [my username]

But the problem persists. I still do not have permission to edit and save files on my hard drive (/dev/sdc). I can only view them and read them. Is there anyway someone can help me with this?

Appreciatively!

First, I recommend you go back to the Terminal and undo the chown operation that you performed on the /dev/sdc device. That is neither necessary nor (generally speaking) helpful in gaining access for user to the files on the disk.

Instead of changing the permissions of the device, you instead should instead mount the device (this probably happens automatically when you plug it into the computer) and change the permissions on the mount point and the files it contains. So if the volume is called "Alpha", it would probably be automatically mounted at /media/Alpha, and you could run:

chown -Rv your-username /media/Alpha

If you're logged in with your own limited user account, you'll have to prefix that command with sudo:

sudo chown -Rv your-username /media/Alpha

You can also use Nautilus (the graphical file browser) to change ownership/permissions, and many people prefer to do it that way. Navigate to /media (or whatever the parent directory is of the mount point), right-click on Alpha (or whatever the volume is called), click Properties, then go to the Permissions tab. You may (for example, if you want to change ownership) need to do this in a Nautilus window that is running as root. To run a Nautilus window as root when logged in as a non-root user, press Alt+F2 and type

gksu nautilus

into the text box, then press enter.

By default, in Ubuntu only administrators (members of the group called admin) can elevate their privileges to root with sudo (or gksu/gksudo).

You might find that you cannot change ownership or permissions on a mounted drive or its contents, using the above method. Sometimes a drive is mounted in such a way that Unix-style ownership and permissions are not respected (especially if the drive has a filesystem that uses a different system of permissions, like NTFS/HPFS/HFS/HFS+, or no system of permissions, like vfat/FAT16/FAT32/exFAT), and the default permissions that get assigned when this happens might or might not enable you to use the drive as you wish. If you attempt to change permissions but when you check you find that they actually don't have the new permissions (as though they have instantly "popped back" to what they were before), this might be the case. In that case, open a Terminal window and run:

mount

Then select all the text in the Terminal (Edit > Select All), copy it to the clipboard (Edit > Copy), and paste it here. That should reveal specifics about the situation.

By the way, I noticed you were talking about being "signed in as root," and that the command you used to change ownership of /dev/sdc did not have "sudo" at the beginning of it. That suggests that you have enabled the root user account, rather than using sudo (and graphical frontends for sudo like gksu and gksudo, where appropriate). You are perfectly free to do this, but it is not recommended; in Ubuntu, the recommended way to perform administrative tasks is with sudo/gksu/gksudo, and most users who try this out find that it works well. See https://help.ubuntu.com/community/RootSudo. If you do choose to start using sudo (as is "the Ubuntu way"), that page also tells you how to re-disable root logins (which is recommended).

Ron (ronald17b95) said : #4

Eliah,

You're quite a genius my friend! Thanks so much for your help. I have successfully changed the permissions on the mount point by running the following command in the Terminal:

sudo chown -Rv your-username /media/Alpha

You mentioned I should "undo the chown operation that you performed on the /dev/sdc device." How can I do that?

You are right, I have long used root by singing in as

su

in the terminal and then typing in my root password. I have a bit of experience with Debian and so I thought that is the usual way in Ubuntu as well. Now that you explained there are other ways of making changes as root e.g., sudo, I will make sure not to use my root account any longer. Thanks for bringing this to my attention. When it comes to Linux I am really a novice. Any help I can get to educate myself is great.

Appreciatively!

R

To undo the chown operation on /dev/sdc, chown it back to its previous owner. This is typically root (and the group owner is also typically disk). So:

sudo chown root:disk /dev/sdc

(If you're logged on as root or otherwise in a root shell, you don't need the sudo at the beginning.)

However, if you've removed and reattached the device, this may have happened automatically. Plus, you might want to double check that these are the correct user and group owners. So you can get information on *all* /dev/sd... devices (so you can see if /dev/sdc is back to normal, and you can look at the others to compare their ownerships):

ls -l /dev/sd*

Correction: "and the group owner is also typically disk" --> "and the group owner is typically disk"

Ron (ronald17b95) said : #7

Thanks Eliah Kagan, that solved my question.