4

I'm on a Linux machine trying to mount an SMB share inside a big network via my Active Directory username:

mount -t cifs -o username=myuser,domain=mydomain //server/share /mount/path

After the password + succesful mount I try touch /mount/path/test.txt, but I get permission denied. So many search results (this one is the biggest in terms of upvotes) suggest that because of using sudo mount the write permissions are only granted to root and not your normal user. But in my case, I am root because I use sudo -i first, everything happens on root console. /mount/path belongs to root and everything below it too (the content of the mounted drive). I've tried to solve this for 2 hours now but I'm so stuck. Does anyone know why I can not even write to the drive as root?

R-obert
  • 141
  • 1
  • 1
  • 2

1 Answers1

7

CIFS share will be mounted as root using your command, so normal user not able write anything there. You need to specify the user and group ID for whom you want to assign read/write permission. You can try with below command.

sudo mount -t cifs -o username=myuser,password=yourpassword,domain=mydomain,uid=yourUID,gid=yourGID,forceuid,forcegid //server/share /mount/path

Also you can use id command to get uid and gid automatically like below.

sudo mount -t cifs -o username=myuser,password=yourpassword,domain=mydomain,uid=$(id -u),gid=$(id -g),forceuid,forcegid //server/share /mount/path
Vaibhav Panmand
  • 1,038
  • 7
  • 17
  • But why would I need to do that? I am root, I'm on the root console! Shouldn't I be able to write to the drive if everything on the mount point belongs to root? – R-obert Sep 09 '21 at 17:15
  • 1
    @R-obert did you cross check if your user is included in 'write list' of samba share – Vaibhav Panmand Sep 09 '21 at 17:23
  • I'm not using 'my' user! I use my user only to login and then I switch to ´sudo -i´. Or do you mean that root user? Is that 'write list' something on my Linux machine (/etc/sambda/smb.conf?) or on the machine that is providing the share (SMB server)? I feel like I need to read a tutorial about where my Linux user (root) comes into play and where my AD user comes into play which I'm using to connect the drive. – R-obert Sep 09 '21 at 17:49
  • I forgot to say that using your command from the answer also results in permission denied. – R-obert Sep 09 '21 at 18:01
  • Does the AD name and the Linux username have to be the same or something? – R-obert Sep 09 '21 at 18:22
  • @R-obert it not needed to be same, but the username you are using to mount drive must have write permission in samba server share configuration. – Vaibhav Panmand Sep 09 '21 at 18:41
  • What Vaibhav is asking is that, since you have specified `username=myuser` in the mount command, have you verified that the Samba user `myuser@mydomain` has write permissions to the share `//server/share`? – tsc_chazz Sep 09 '21 at 19:03
  • My username on the Linux machine is the same as my Active Directory account name. When I log into a Windows PC in our company via my AD account, I can attach the drive and write to it. So "myuser" must have the permission by the SMB server... – R-obert Sep 09 '21 at 20:31
  • I'm sure you've looked in `/etc/fstab` to confirm that the CIFS mount is not defined there, or if it is, it's not defined as being readonly. If `//server` is a Windows machine, I have few other ideas. – tsc_chazz Sep 09 '21 at 20:47
  • Yes, there's nothing ! I'm trying to mount it manually before I tell the system to mount it upon boot. I do not know the OS of the server unfortunately. – R-obert Sep 10 '21 at 08:50
  • 1
    I'm so sorry, my AD account seems to no longer have write permissions for the share. I do not know why that is no longer the case but I'm very sorry for having given wrong information here! I have just rechecked my write permission on a Windows PC just to make sure. Thank you for your help, I'll post again upon success. – R-obert Sep 10 '21 at 09:00