Change ownership of a share drive

10,020

It is not possible to change permissions on a windows share when it's already mounted, but it is possible to change them during the mount.

first unmount your share with:

sudo umount /mnt/windowshare/

then mount the share again with these new arguments:

sudo mount.cifs -o username=myuser,uid=youruser,gid=yourgroup //xxx.xxx.xx.xx/myfolder /mnt/windowsshare/

quoting from the mount.cifs man

uid=arg sets the uid that will own all files or directories on the mounted filesystem when the server does not provide ownership information. It may be specified as either a username or a numeric uid. When not specified, the default is uid 0. The mount.cifs helper must be at version 1.10 or higher to support specifying the uid in non-numeric form.

gid=arg sets the gid that will own all files or directories on the mounted filesystem when the server does not provide ownership information. It may be specified as either a groupname or a numeric gid. When not specified, the default is gid 0. The mount.cifs helper must be at version 1.10 or higher to support specifying the gid in non-numeric form.

link to the mount.cifs man

to find your user open a terminal and run this command:

whoami

to find your group run this command: ( in this case the right group will be the first from the left )

groups
Share:
10,020

Related videos on Youtube

Tak
Author by

Tak

Apparently, this user prefers to keep an air of mystery about them

Updated on September 18, 2022

Comments

  • Tak
    Tak almost 2 years

    I have a windows machine locally connected to my linux machine. There is a shared folder on the windows machine, which I mounted on my linux machine using sudo mount -t cifs -o username=myuser //xxx.xxx.xx.xx/myfolder /mnt/windowsshare/ and it's mounted successfully and I can see the files and folders.

    The problem now is that I'm trying to create a folder inside the mounted share but I can't. I've checked the permissions of the mounted folder and it says

    "You are not the owner, so you cannot change these permissions"

    as shown below:

    enter image description here

    I've tried running sudo chmod -R 777 /mnt/windowshare and sudo chown -R isa /mnt/windowshare but it says chmod:

    changing permissions of '/mnt/windowshare/.?00000002202011111110e5(and many other chars)': No such file or directory

    then I stop the command using ctrl+c

    Any advice how I can have control access over this folder on my linux machine?

    • D'Arcy Nader
      D'Arcy Nader about 6 years
      can you create a file on the share with root ?
    • Tak
      Tak about 6 years
      @D'ArcyNader How I can do that?
    • D'Arcy Nader
      D'Arcy Nader about 6 years
      use this command sudo touch /mnt/windowshare/testfilename
    • Tak
      Tak about 6 years
      @D'ArcyNader I just tested and yes, I can create a file on the share with root. But it's read only like everything in the shared folder.
    • D'Arcy Nader
      D'Arcy Nader about 6 years
      i'm writing an answer for you.
  • Tak
    Tak about 6 years
    Thanks for that. When I try do this sudo mount.cifs -o username=myuser,uid=youruser,gid=yourgroup //xxx.xxx.xx.xx/myfolder /mnt/windowsshare/ it asks for the password of the network share and then it works, but when I tried doing this sudo mount.cifs -o username=myuser,password=mypassword,uid=youruser,gid=yourgro‌​up //xxx.xxx.xx.xx/myfolder /mnt/windowsshare/ by adding the password, it says permission denied, not sure why? Also when how I can make this permenant so that I don't have to rewrite the command every time I lose connection or restart the computer?
  • D'Arcy Nader
    D'Arcy Nader about 6 years
    hi @Tak i'm at work right now and i don't have time to help you. i'm sorry, perhaps if you open another question someone will help you faster than me.