Wednesday, June 17, 2009

Mounting samba share in Ubuntu

Mounting samba share in Ubuntu

After my move to Ubuntu I was finding the built in network browser very slow. I decided to see if there was a way I could mount my SMB shares to the /media directory so they show up as a drive on the desktop. Better yet, I wanted to make it so they mount automatically on boot.

Here are the steps:

1. Execute the following command to install smbfs:

    sudo apt-get install smbfs

2. Create a folder inside of the /media directory to mount the share on:

    sudo mkdir /media/Storage

3. You can run the following command to mount a share manually:

    sudo mount -t cifs //fileserver/Storage  -o username=,password=<password>,uid=<userid>,gid=<group_id>,sec=ntlm /media/Storage

    Note: Change <user> to your linux username. The uid=<user>,gid=users is important because if you don't use that, only root will have access to write files to the mounted share.

4. You can edit the mount list in /etc/fstab to have the drive mount on boot. And add this line to the bottom of the fstab file, but change //fileserver/Storage to the path to your share on your server.

    sudo gedit /etc/fstab

    //fileserver/Storage /media/Storage cifs username=,password=,uid=,gid=users 0 0

    In the above line change <user> to your user account in both spots. Before this will work you also have to create the .smbcredentials file in the above users home directory.

    sudo vim ~/.smbcredentials

5. Add the following information to the file, but change Guest to your SMB username and add your SMB password.

    username=guest
    password=guest

    Note: My fileserver allows Guest access to the shares, so I just use the username Guest with no password. If your server requires a username and password put it in here.

6. To test if the auto mount works just run the following command

    sudo mount -a

    You should see a new mount show up on your desktop for the drive.

7. If you are worried about people who dont have root access being able to read login and password from the .smbcredentials file you can give only root and admin group access by typing

    sudo chmod o- ~/.smbcredentials

    Note:

    1. Do not try and mount a folder on a share, it wont work. The source for an SMB mount has to be a share.

    2. Do not put a trailing “/” on the share path or the directory path, it will cause it to fail.

SMB Shares with spaces in the names:

If you have an SMB share with a space in the path you can replace the space with \040. For example:

    //fileserver/Storage\040Folder /media/Storage cifs credentials=/home/rajeev/.smbcredentials,uid=,gid=users 0 0

    Note: Change USER to your linux username. This will mount the share “//fileserver/Storage Share” to the directory “/media/Storage Share” and give USER r/w access to it. If you are using the mount command you dont have to do this, you can just put the source share and the destination directory into quotes like this:

    sudo mount -t cifs "//fileserver/Storage Share" "/media/Storage Share" -o uid=,gid=users

    Example:

    //192.168.1.1/documents /mnt/documents cifs credentials=/home/rajeev/.smbcredentials,uid=rajeev,gid=users 0 0
Post a Comment