Correct way of mounting a Windows share

I mounted a Windows share to my Ubuntu 11.10 system via adding the following line to the /etc/fstab:

//serveraddr/sharedfolder /mnt/foldername/ smbfs credentials=/home/myname/.smbpasswd 0 0

using the tutorial here.

But there's a problem with the permissions. The owner of the mount folder is root. I can not create any folders or files in the mounted point is I don't become the root. Even I can not change the ownership to my default user via

sudo chown -R myname .

I googled and saw that it might stem from the fact that Windows file formats (fat32/ntfs) can not save ownership. But when I connect to the same location via samba as

smb://serveraddr/sharedfolder

by providing my credentials, I have the privileges to write without being the root.

How can I make it to let me write to the mounted folder?


Solution 1:

Don't use smbfs, the new protocol's name is cifs and its part of the package cifs-tools (install it if you did not already.

Instead use this line in your fstab

//server/share /mnt/mountname cifs username=server_user,password=user_password,iocharset=utf8,file_mode=0777,dir_mode=07‌​77 0 0

Where

server = your server that you are trying to access
share = mapped share on that server
/mnt/mountname = any folder that you created with sudo /mnt/<folder_name>
username = the name of the user on that server that can access the mount
password = the password for that user

After that you can test with sudo mount -a, if you dont get any faults you can safely reboot to find your shares mounted in /mnt/<folder_name>.

To use a credentials file instead of the username and password parameters on the fstab you can create a file with those 2 lines so that your username and password are not explicitly shown in the fstab

sudo nano /etc/cifspwd

Add these lines to the file

username=<username on server>
password=<password for that username>

Press ctrl+x keys and when asked press y to save the file.

Secure it with

sudo chmod 600 /etc/cifspwd

Use this line instead of the previous

//server/share /mnt/mountname cifs credentials=/etc/cifspwd,iocharset=utf8,file_mode=0777,dir_mode=07‌​77 0 0

After this it will be safe to reboot and you mount should be mounted and your details secured.