Skip to main content

Solving Ubuntu permission problems when mounting a Windows SAMBA drive

After using Ubuntu desktop for a while I decided that a backup of my files would be a good idea and so went about attempting to mount and copy a whole host of files.

I attempted to mount the SAMBA drive running on my Windows fileserver as myself:
smbmount //backups/andrew.beacock shares/backups -o username=andrew.beacock,password=********
but was told that I didn't have permission to, only root can mount to SAMBA drives. So I popped the word 'sudo' in front of the command and tried again. This time it connected successfully and I was able to browse around the shared directories.

I then attempted to use rsync to back up my important folders but ran into problems again. It complained that I didn't have permission to delete files off my share, so again I popped the sudo command in front of the rsync command and thought it was me being stupid.

I then ran into a really strange problem where even though I was running as root and the files on the server were owned by root I didn't have permission to delete some of the files and directories!

After wiping the problem files from the fileserver as root (the problem was due to the share being mounted as root rather than as me), I was advised to set the 's bit' of smbmount and trying again. I did that and Ubuntu just complained that smbmount was not allowed to run with the 's bit' set!

So I went off to Google and found the answer on the LinuxQuestions.org forum.

Although smbmount cannot be setuid root, smbmnt (a program used by smbmount) can. This means that you can run smbmount as your own user and it will setuid to root when connecting to the SAMBA mount point.

Here's what I did to get it all working:

Change the permissions of /usr/bin/smbmnt to be setuid root:
cd /usr/bin
sudo chmod u+s smbmnt


Check that the s bit is set:
abeacock@ab100:/usr/bin$ ls -l smb*
-rwxr-xr-x 1 root root 1588348 2006-05-17 11:05 smbcacls
-rwxr-xr-x 1 root root 775340 2006-05-17 11:05 smbclient
-rwxr-xr-x 1 root root 512332 2006-05-17 11:04 smbcontrol
-rwxr-xr-x 1 root root 1493884 2006-05-17 11:05 smbcquotas
-rwxr-xr-x 1 root root 1551224 2006-05-17 11:05 smbget
-rwsr-xr-x 1 root root 8488 2006-05-17 11:05 smbmnt
-rwxr-xr-x 1 root root 709888 2006-05-17 11:05 smbmount
-rwxr-xr-x 1 root root 1500284 2006-05-17 11:05 smbpasswd
-rwxr-xr-x 1 root root 700872 2006-05-17 11:05 smbspool
-rwxr-xr-x 1 root root 498860 2006-05-17 11:04 smbstatus
-rwxr-xr-x 1 root root 4896 2006-05-17 11:04 smbtar
-rwxr-xr-x 1 root root 705704 2006-05-17 11:05 smbtree
-rwxr-xr-x 1 root root 6108 2006-05-17 11:05 smbumount


Mount the Windows SAMBA share as yourself (no sudo required):
smbmount //backups/andrew.beacock shares/backups -o username=andrew.beacock,password=********

You can now copy files over as yourself and all the permissions remain correct!

Technorati Tags: , , , , , , , ,

Comments