MountWindowsSharesPermanently

Revision 12 as of 2006-04-26 13:18:15

Clear message

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 File System installation

sudo apt-get install smbfs

Mounting unprotected network folders

Assumed that:

  • Network connections have been configured properly.
  • The Windows computer name is servername, this can be either an IP address or an assigned name.

  • The name of the share is sharename.

  • You want to mount the share in a folder mountname.

First, let's create the mount folder. You will need a separate folder for each mount.

sudo mkdir /media/''mountname''

Then edit your /etc/fstab file (you need root privileges) to add this line:

//''servername''/''sharename''  /media/''mountname''  smbfs  rw  0  0

Mount password protected network folders

Assume the previous, plus:

  • Share username on Windows computer is myusername.

  • Share password on Windows computer is mypassword.

You could add the following to /etc/fstab:

//''servername''/''sharename''  /media/''mountname''  smbfs  username=''myusername'',password=''mypassword''  0  0

However, 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 ~/.smbcredentials

Add the following lines:

username=''myusername''
password=''mypassword''

and save it.

Modify 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

Now add the following line for Read and write permission for everyone:

//''servername''/''sharename''  /media/''mountname''  smbfs  credentials=~/.smbcredentials,dmask=777,fmask=777  0  0

or for only read permission:

//''servername''/''sharename''  /media/''mountname''  smbfs  credentials=~/.smbcredentials  0  0

Special permissions

If you need special permission (like chmod etc.) you need to add uid or gid flag. You can set either UID or username

//''servername''/''sharename''  /media/''mountname''  smbfs   uid=uros,credentials=~/.smbcredentials,dmask=777,fmask=777   0       0

In that case /media/sharename will be owned by user uros

Mounting a Share with Read/Write rights with a regular User (Without Prompt)

Open a Terminal and type:

id 

This should output something similar to:

uid=1000(craize) gid=1000(craize) groups=...

So for my user (craize) the User ID is 1000 and the Group ID is 1000 too.

Add the following to /etc/fstab:

//''servername''/''sharename''  /media/''mountname''  smbfs  defaults,uid=1000,gid=1000,credentials=~/.smbpasswd,umask=777  0  0

After you added the entry to /etc/fstab type:

sudo mount -a

This will (re)mount all entries in /etc/fstab

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]


CategoryDocumentation