What's the easiest way to mount Windows share as a local folder in home directory?

129,483

Solution 1

Suppose you have a directory called mounts in your home directory in which you want various Samba shares to be mounted. Suppose further that you are specifically interested in mounting a share called sharename from a remote machine called hostname (this could also be an IP address), and on that remote machine your username is username. First, create the mount point:

mkdir ~/mounts/sharename

Then mount the share:

sudo mount.cifs //hostname/sharename ~/mounts/sharename -o user=username

In Ubuntu 12.04 LTS and earlier, if you don't have the mount.cifs command, you can either install the cifs-utils Install cifs-utils package, or use smbmount instead (which is, in turn, provided by the smbfs Install smbfs package).

sudo smbmount //hostname/sharename ~/mounts/sharename -o user=username

(smbmount is not available in Ubuntu 12.10 or higher, at least so far, but you can use mount.cifs instead. Thanks to HDave for pointing this out.)

You may be prompted for your password on the local machine, to run the command as root. Then you'll be prompted for your password on the remote machine, to log in so you can mount the share.

Solution 2

  • Open your file manager, i.e. click the icon for Home Folder
  • Observe up at the top of the screen is the Menu for the File Manager (as opposed to at the top of its window);
  • Click FileConnect to Server...; a window should open titled Connect to Server
  • Click into its drop-down box titled Type; choose Windows share (i.e. change from the default of Public FTP)
  • Enter the Server (the name if it can be resolved by DNS or its IP address
  • Enter the Share (i.e the items you'd otherwise see in a windows share as the Share component of '\\Server\Share')
  • Enter into Folder the name of any particular directory on the share that you'd like the mount to position at
  • Enter any/optional User Details
  • The Share should Mount and appear in the File Manager window on the left list under Network
  • You might then like to create a bookmark for that mount. Again, from the File Manager menu at the top of the screen: Bookmarks → Add bookmark (after first clicking on/highlighting the share you have just mounted).

Solution 3

Not sure if you are still looking for something easy, I just found it:

All the shares you have opened are mounted automatically in your home folder under /home/.gvfs.

Any application can recognize and access the shares as if they were normal folders, as long as you point the application to the files or folders you want in /home/.gvfs

Solution 4

Why would you want to use Samba to access files on your Linux server? Samba is meant for accessing Windows network shares and services.

Use sshfs instead, there is no setup necessary at all and you get "proper" mount points that are recognized by any application:

sudo apt-get install sshfs

Mount the remote filesystem with

sshfs user@host:/path /local/mount/point

and unmount with

fusermount -u /local/mount/point
Share:
129,483

Related videos on Youtube

HDave
Author by

HDave

Architect, developer, and most importantly, user.

Updated on September 18, 2022

Comments

  • HDave
    HDave over 1 year

    Via Gnome Nautilus I can easily mount Samba shares from my Ubuntu Server. However, these "mounts" are kinda of fake. Many applications I run do not recognize that Gnome has mounted these server folders and therefore cannot open files off my server.

    In the past I created an /etc/fstab entry and mounted them globally, the /mnt folder, but this isn't going to work as other people share my Ubuntu laptop.

    What's the easiest way to create a "real" samba mount in my (and other people's) home directory? It's fine if its a command or a GUI application that can run when I log in. These server folders don't have to be mounted all the time.

    • Admin
      Admin almost 12 years
      Why would you want to use Samba to access files on your Linux server? Samba is meant for accessing Windows network shares and services.
    • Admin
      Admin almost 12 years
      Because NFS is a pain to set up on the server, and even harder to get working from Windows clients. Ditto with sshfs and others.
    • Admin
      Admin almost 12 years
      sshfs requires no setup whatsoever on the server other than sshd running which you'll need anyway. So even if you have samba running to serve Windows clients I wouldn't use it for Linux clients. Incidentally dokan is a brilliant sshfs client for Windows which is easy to set up.
    • Admin
      Admin almost 12 years
      I've set up sshfs on Windows...it works well. But why tweak a bunch of windows/mac machines when samba server works so well and is so easy to setup?
    • Admin
      Admin almost 12 years
      Samba is certainly a sensible option for serving files to Windows/Mac clients. I just don't think it's necessary when serving only Linux clients, which is how I read your question.
    • Admin
      Admin over 7 years
      Instructions updated for newer versions of Ubuntu: wiki.ubuntu.com/MountWindowsSharesPermanently
  • HDave
    HDave over 12 years
    Had to do a sudo apt-get install smbfs first though.
  • Logi
    Logi over 12 years
    Also needed sudo apt-get install smbfs first. Then the mount worked correctly on my end. Note that I replaced hostname with the IP address of the server. (The server is a WinXP box) Not sure why the computer name of the XP box did not work for me. THANKS GUYS!
  • HDave
    HDave over 12 years
    Doing this via Nautilus is what I meant by the mount being a "fake" mount. This "mount" is only recognized by a small handful of Gnome applications. Try going to a command line and doing an "ls", or try opening up a file on the mount from VLC or some other apps that don't use the Gnome file dialog and you will find your mounts are not there.
  • lmat - Reinstate Monica
    lmat - Reinstate Monica about 12 years
    @HDave ls worked for me. cd ~/.gvfs then ls and there should be the mount. You can symlink to wherever you want from there.
  • HDave
    HDave over 11 years
    This is correct, but they won't be there when you first log in. You have to browse to them in Nautilus first, which is awkward.
  • HDave
    HDave over 11 years
    Because you have other Windows clients on your LAN. And yes, they can run sshfs too, but Samba works great and is just easier all around.
  • kynan
    kynan over 11 years
    Fair enough, that doesn't become clear from your question though. Also, nothing stops you from accessing your Linux server via SSHFS from Linux and via Samba from Windows/Mac. You can even access the same share in multiple ways.
  • HDave
    HDave over 11 years
    This is now broken in 12.10. Find the bug and workaround here: bugs.launchpad.net/ubuntu/+source/cifs-utils/+bug/1095294
  • Calmarius
    Calmarius about 11 years
    I'm getting: mount error(12): Cannot allocate memory (They say I need registry hack, but I have no access to the Windows side...)
  • Eliah Kagan
    Eliah Kagan about 11 years
    @Calmarius I recommend posting a new question about this problem. When you do, please provide as many details as possible. Please also make sure to identify who it is who says you have to do something with the Windows registry, with a link or links if possible; what machine(s) the "hack" allegedly has to be performed on; and anything you know about the recommendation or, if you've tried it, exactly what you did and what happened. Especially if the error you're getting is a server error, this appears beyond the scope of this particular question.
  • Ola Tuvesson
    Ola Tuvesson almost 10 years
    The manual CIFS solution is the best option unless you want to add an entry to your fstab file for automatic mounting - there is nothing to stop you from specifying a mount directory outside /mnt (for example a subfolder in your home directory). One important detail missing from this answer is that you will not become the owner of the mounted directory with the mount.cifs command as given. If you need full control of the share after mounting you should set the owner with the uid=1234 and gid=1234 CIFS options. You can find your user id and group id by running sudo id myusername HTH!
  • Ola Tuvesson
    Ola Tuvesson almost 10 years
    To clarify, in order for me to own the mounted share as a normal user I need to run $ sudo mount.cifs //Server/Share ~/Mountpoint -o user=MyUsername,uid=1000,gid=1000 Without supplying the uid and gid the mounted share will be owned by root. Owning the share is essential for example if it is under some form of CVS and you want to be able to perform updates/commits as yourself.
  • Marecky
    Marecky over 3 years
    In Ubuntu 18.04 (Ubuntu Budgie 18.04) I had to sudo apt install cifs-utils