MountWindowsSharesPermanently

Differences between revisions 7 and 8
Revision 7 as of 2006-04-14 20:10:25
Size: 4800
Editor: vodsl-3858
Comment: Fixed a Typo - Added Mounting a Share with Read/Write rights with a regular User
Revision 8 as of 2006-04-15 09:28:12
Size: 4967
Editor: vodsl-3858
Comment: Added Table of Contents
Deletions are marked like this. Additions are marked like this.
Line 2: Line 2:
||<tablestyle="float:right; font-size: 0.9em; width:40%; background:#F1F1ED; margin: 0 0 1em 1em;" style="padding:0.5em;">'''Contents'''[[BR]][[TableOfContents]]||

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 password protected 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.

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

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

Mount non-password protected network folders

If your shares aren't password protected, like most Windows shares, then you'll want to read this section.

Assumed that:

  • Network connections have been configured properly
  • Network computer's IP: 192.168.0.1
  • Shared folder's name: linux
  • Local mount folder: /media/sharename

Add this line to /etc/fstab:

//192.168.0.1/linux       /media/sharename   smbfs   rw    0   0

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=4(adm),20(dialout),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),106(lpadmin),110(scanner),112(admin),1000(craize)

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

Now lets store the Username and Password of the Samba share in our Home Directory, leaving it only readable and writeable by oursleves. So Open up any Terminal with the user you want to give Write Access and type:

cd $home
echo username=mywindowsusername > .smbpasswd
echo password=mywindowspassword >> .smbpasswd
chmod 600 .smbpasswd
  • Replace mywindowsusername with Your Windows Username

  • Replace mywindowsPassword with Your Windows Password

So now that we created a secure Credentials file for own regular user, here's a sample for /etc/fstab where we assumed the following:

  • 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

//192.168.0.1/linux /media/sharename smbfs defaults,uid=1000,gid=1000,credentials=/home/craize/.smbpasswd,credentials=/home/craize/.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

MountWindowsSharesPermanently (last edited 2024-04-18 09:12:09 by sally-makin)