Correct way of mounting a Windows share
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=0777 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=0777 0 0
After this it will be safe to reboot and you mount should be mounted and your details secured.
Related videos on Youtube
![Ishara](https://i.stack.imgur.com/sCyF5.jpg?s=256&g=1)
Ishara
Updated on September 18, 2022Comments
-
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 viasudo 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 over 12 yearsIf this does not work please paste the output of
cat ~/.smbpasswd
. -
Ishara over 12 years@bbrunopereira81: It doesn't work.
cat .smbpasswd
givesuser=name.surname pass=******* dom=domainname
-
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_mode=0777
. if you get faults write them down. -
Bruno Pereira over 12 yearsps: its all one line!
-
Ishara over 12 years@bbrunopereira81: It works fine after doing within the terminal. The files can be editable.
-
Bruno Pereira over 12 yearsgreat, 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,mode=0777,dir_mode=0777 0 0' after the line is there just mount everything with
sudo mount -a`. -
Bruno Pereira over 12 yearsedited 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 withsudo mkdir /mnt/<folder>
. -
Bruno Pereira over 12 yearswelcome, gl and hf ;)
-
Bruno Pereira over 12 yearsAdded information for the credentials file, you can also use that method.
-
Ishara over 12 yearsActually, I've done it that way :)
-
Bruno Pereira over 12 years@İsmailArı good, good. anyways gl!
-
Avian00 over 11 yearsI 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 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 almost 11 yearsConfirming that "mode" should be replaced with "file_mode" in 12.10!
-
CatShoes almost 11 yearsOn 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=0777,nounix 0 0
-
KevinC over 9 yearsIs 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 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 theroot
owner -
Timofey almost 9 yearsanswering my own question: add
uid=user_id,gid=group_id
to the list of options into the fstab -
Richard Fawcett over 8 yearsThese days, the package name for
cifs
seems to becifs-utils
.