How to mount remote Windows shares

Author: Akemi Yagi (aka toracat): amyagi at gmail dot com

OK, we live in the wonderful world of Linux. BUT, for many of us having to deal with Windows is a fact of life.  I, for example, use Linux servers to back up Windows files. I do this by mounting Windows shares on the server using samba (cifs) and accessing the files as if they are local. This page is a mini-howto for mounting remote Windows shares.

The following names are used in our examples.

remote Windows machine name:  winbox
share name on winbox:  getme
username: sushi
password:  yummy
Basic method
Create a local mount point.  For example:

mkdir /mnt/win

Edit the /etc/fstab file and add a line like:

//winbox/getme   /mnt/win   cifs   user,uid=500,rw,noauto,suid,username=sushi,password=yummy  0 0

The Windows share gets mounted on boot or by the command mount /mnt/win . In this example, local user (uid=500) will become the owner of the mounted files.
Better Method
The above method has a little problem.  Username and password are visible to everyone.  We can avoid this by using a credentials file.

//winbox/getme   /mnt/win   cifs   user,uid=500,rw,noauto,suid,credentials=/root/secret.txt 0 0

And the /root/secret.txt file looks like this:

username=sushi
password=yummy

This file can be placed anywhere. Make sure it is not readable by others.
Even better method
Once mounted through /etc/fstab it remains mounted unless you umount it. This might cause problems if the remote share becomes unavailable, resulting in stale mounts. For example, the Windows machine you are connecting to might crash (surprise!) or the network might go down.

Automount comes in handy. Here is what you need to do. First edit the /etc/auto.master file to add a line like:

/misc /auto.misc
(You can use any directory; make sure that directory exists)

Then edit the /auto.misc file you just entered:

winbox -fstype=cifs,rw,noperm,user=sushi,pass=yummy ://winbox/getme

Or by using the same credentials file as above:

winbox -fstype=cifs,rw,noperm,credentials=/root/secret.txt ://winbox/getme

Note that /etc/auto.misc can be made world-unreadable, so, use of the credentials file is not as important as in the previous method.

Now try accessing the share by ls /misc/winbox or by cd /misc/winbox . It is dynamically loaded upon access. After some inactivity (default 60 seconds), the share will be unmounted.

Congratulations! You’re done.

[Note for CentOS 5.0 users]

There is a bug in the cifs module of kernel 2.6.18 that CentOS 5.0 (RHEL 5.0) uses. This bug causes kernel oopses or system crashes in an unpredictable manner. Fortunately, the CentOS team provides a bug-fixed version of the cifs module. Please see the following link for more details.

http://bugs.centos.org/view.php?id=1776

How To Browse Windows Shares
If you just need to browse Windows files, you do not need to mount them. There are easy ways to access them from your file browser.

In Konqueror, Go -> Network folders -> Samba Shares

In nautilus, Places -> Network -> Windows Network

To go to a specific share more quickly, you can type directly in the Location box of konqueror:
smb://winbox/sushi

If you use nautilus, type a / first (thanks to Johnny Hughes for this hint).

Read more at toracat.freeshell.org

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s