MountWindowsSharesPermanently
This will help you mounting smbfs shares permanently. These can be shares on a Windows computer or on a Linux/UNIX server running Samba.
Samba installation
sudo apt-get install samba sudo apt-get install smbfs
Now you need to restart the service:
sudo /etc/init.d/samba restart
Mount network folders
Assumed that:
- Network connections have been configured properly
- Network computer's IP: 192.168.0.1
- Network computer's Username: myusername
- Network computer's Password: mypassword
- Shared folder's name: linux
- Local mount folder: /media/sharename
Let's create the mount folder
sudo mkdir /media/sharename
The /etc/fstab is readable by everyone so it obviously wouldn't be a good idea to have your Windows password in it. The way to get around this is by using what is known as a credentials file. This is a file that contains just the username and password.
sudo gedit /root/.smbcredentials
Add the following lines:
username=myusername password=mypassword
and save it.
Modifify the permissions on the file so only you have permission to read and write to it. The only thing in the file is your Windows username and password.
sudo chmod 600 .smbcredentials
Make a backup of your fstab:
sudo cp /etc/fstab /etc/fstab_backup
Now edit your fstab:
sudo gedit /etc/fstab
Now add the following line for Read and write permission for everyone:
//192.168.0.1/linux /media/sharename smbfs credentials=/root/.smbcredentials,dmask=777,fmask=777 0 0
or for only read permission:
//192.168.0.1/linux /media/sharename smbfs credentials=/root/.smbcredentials 0 0
and save it.
If you need special permission (like chmod etc.) you need to add uid or gid flag. You can set either UID or username
//192.168.0.1/linux /media/sharename smbfs uid=uros,credentials=/root/.smbcredentials,dmask=777,fmask=777 0 0
In that case /media/sharename will be owned by user uros
Troubleshooting
If your files with special characters/umlauts are displayed like that ?bungen (invalid encoding), then you need to make some changes in fstab.
sudo gedit /etc/fstab
You need to append the following parameters:
,codepage=cp850,iocharset=utf8
Example:
//192.168.0.1/linux /media/sharename smbfs credentials=/root/.smbcredentials,codepage=cp850,iocharset=utf8,dmask=777,fmask=777 0 0
Credits: [http://www.ubuntu-de.org/wiki/netzwerk:samba_mounten UbuntuUsers.de]