Correct way of mounting a Windows share

82,606

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.

Share:
82,606

Related videos on Youtube

Ishara
Author by

Ishara

Updated on September 18, 2022

Comments

  • Ishara
    Ishara almost 2 years

    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?

  • Bruno Pereira
    Bruno Pereira over 12 years
    If this does not work please paste the output of cat ~/.smbpasswd.
  • Ishara
    Ishara over 12 years
    @bbrunopereira81: It doesn't work. cat .smbpasswd gives user=name.surname pass=******* dom=domainname
  • Bruno Pereira
    Bruno Pereira over 12 years
    @İsmailArı why do you have domain? are you part of a domain??? try using all on the same line instead of making a file apart for the credentials, try this on a terminal: sudo mount -t cifs //ip_from_windows_pc/sharename /mnt/share -o username=windows_username,password=windows_password_for_user‌​,iocharset=utf8,file‌​_‌​mode=0777,dir_mod‌​e=0777. if you get faults write them down.
  • Bruno Pereira
    Bruno Pereira over 12 years
    ps: its all one line!
  • Ishara
    Ishara over 12 years
    @bbrunopereira81: It works fine after doing within the terminal. The files can be editable.
  • Bruno Pereira
    Bruno Pereira over 12 years
    great, now all you need to do is add this to your fstab: //server/share /mnt/mountname cifs username=server_user,password=user_password,iocharset=utf8,m‌​ode=0777,dir_mode=07‌​77 0 0' after the line is there just mount everything with sudo mount -a`.
  • Bruno Pereira
    Bruno Pereira over 12 years
    edited the answer to reflect the information you gave. btw dont forget that if /mnt/<mountname> is already in use you need to umount /mnt/<mountname>, mountname can be any folder that you create with sudo mkdir /mnt/<folder>.
  • Bruno Pereira
    Bruno Pereira over 12 years
    welcome, gl and hf ;)
  • Bruno Pereira
    Bruno Pereira over 12 years
    Added information for the credentials file, you can also use that method.
  • Ishara
    Ishara over 12 years
    Actually, I've done it that way :)
  • Bruno Pereira
    Bruno Pereira over 12 years
    @İsmailArı good, good. anyways gl!
  • Avian00
    Avian00 over 11 years
    I think it's worth noting that in Ubuntu 12.10, "mode" was not a valid parameter. Instead, I had to use "file_mode". Also, I'm not sure I entirely agree with general permissions of 0777. If you're mounting a private share just for yourself, I think something like "file_mode=0660,dir_mode=0770" would be more appropriate.
  • Bruno Pereira
    Bruno Pereira over 11 years
    @Avian00 kk, thanks for the mode, will review that. About permissions: well that depends on what needs to be done, not for discussion here I would say.
  • pranay
    pranay almost 11 years
    Confirming that "mode" should be replaced with "file_mode" in 12.10!
  • CatShoes
    CatShoes almost 11 years
    On 12.04 I had to add ,nounix to my options for it to work. Full working solution for me is: //server/share /mnt/mountname cifs credentials=/etc/cifspwd,iocharset=utf8,mode=0777,dir_mode=0‌​7‌​77,nounix 0 0
  • KevinC
    KevinC over 9 years
    Is there a way to have the credentials file use an encrypted hash for your password? Even with the permissions set to 600, any system admin with sudo privileges would be able to read my password in plain text. Thanks!
  • Timofey
    Timofey almost 9 years
    @BrunoPereira do you know how to change a user owner of the folder? sudo chown <myname> /path/to/mounted/share does not change the root owner
  • Timofey
    Timofey almost 9 years
    answering my own question: add uid=user_id,gid=group_id to the list of options into the fstab
  • Richard Fawcett
    Richard Fawcett over 8 years
    These days, the package name for cifs seems to be cifs-utils.