9

I had an old laptop. When it got complaint I removed its hard drive and started using it as external hard disk. It has an 80 GB of memory allocation for the windows C drive partition. But now i don't need that partition anymore. But the problem is I am not able to access that drive to paste files into it. How can I make read and write permission to this drive using terminal?

1
19

If you want to gain ownership of a drive you can use the chown command:

sudo chown -R username:username /media/username/nameofdrive

This gives the user ownership over the drive without allowing permission to unauthorized users and -R makes this command recursive so that ownership also applies to all of the existing individual files on the drive as well and not just the drive itself.

You can also use -R to make chmod recursive as well.

2
  • 2
    To be clear, replace both username parameters with your own username. sudo chown -R mickeymouse:mickeymouse /media/mickeymouse/drivename Mar 28 '18 at 16:18
  • 4
    @JohnnyBizzle You could also do this: sudo chown -R $USER:$USER /media/$USER/drivename
    – mchid
    Mar 29 '18 at 5:07
1

1. Ok technique for files ON an external drive, but the correct technique for files you just copied onto your computer FROM an external drive

This works: recursively (-R) change the username (the part before the colon :) and groupname (the part after the colon :) to your username:

sudo chown -R username:username /media/username/nameofdrive

BUT, the problem with this is that it makes the external disk difficult to share between multiple usernames and/or on multiple computers, because each person on each system who needs access to these files must either have the same username, or must be part of the same groupname. Having the same username only works if it is the same person, so that doesn't always make sense. Having the same groupname is okay if it is consistently the same people using the drive, and they all add themselves to the same group with:

usermod -a -G groupname

BUT, if the groupname doesn't exist on one system, and just shows up as a number, such as 5000, when you look at it with ll (ls -alF), then you can't easily add yourself to the same group because usermod -a -G 5000 produces this error:

$ usermod -a -G 5000
usermod: group '5000' does not exist

2. Sometimes better for files ON an external drive

So, that leads us to this solution: just give full permissions to these files to everyone:

sudo chmod -R 777 /media/username/nameofdrive

BUT, that also marks ALL files as executable, which doesn't really make sense. You don't want to arbitrarily mark every single file as executable, as that can pose a security risk, and also be annoying when every time you double-click a text file to open and edit it, it asks you if you'd like to run/execute it.

3. Better still #1 (or best, if you DO need write permissions for everyone) for files ON an external drive

So, that leads me to my recommendation: give full permissions to everyone (-a, or 'a'll), but only set the executable bit (ie: use +X, NOT +x) if it is either a directory, OR already set for one or more of "user", "group", or "other", like this:

sudo chmod -R a+rwX /media/username/nameofdrive

man chmod says about the capital X versus lower-case x option:

...execute/search only if the file is a directory or already has execute permission for some user (X),...

4. Better still #2 (or best, if you do NOT need write permissions for everyone, ie: if read is enough) for files ON an external drive

BUT, even better still, if you can get away with it: if you don't really need guaranteed write permissions for everyone, just ensure you have at least read permissions for everyone on the drive, like this:

sudo chmod -R a+rX /media/username/nameofdrive

Then, apply permissions -R a+rwX only AFTER copying the files to your local machine from the external drive:

cp -r /media/username/nameofdrive/some_dir ~/some_local_path
# Now add `w`rite for everyone
sudo chmod -R a+rwX ~/some_local_path
# OR (even better!): just make yourself the owner now that it's on your local drive:
sudo chown -R username:username ~/some_local_path

References:

  1. https://superuser.com/questions/454795/how-can-i-do-a-recursive-chmod-only-on-directories/454807#454807
  2. [my repo/file: search this file for chmod to find a bunch of my personal chmod examples here] eRCaGuy_dotfiles/git & Linux cmds, help, tips & tricks - Gabriel.txt

Related

  1. [my answer] https://superuser.com/questions/1271882/convert-ntfs-partition-to-ext4-how-to-copy-the-data/1464264#1464264
0

The drives will be located in /media/username folder. Goto that directory using cd command. And then on terminal

sudo chmod 777 nameofdrive

777 assigns read,write and execute permissions to all users.

2
  • 2
    is that a good idea to assign such wide permissions?
    – BenKoshy
    Jul 26 '18 at 5:08
  • Not working with dual-boot sistem. Dec 28 '19 at 20:22

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.