分享

How to mount remote Windows shares

 农夫子oice 2007-07-06

How to mount remote Windows shares

  1. How to mount remote Windows shares
    1. Basic method
    2. Better Method
    3. Even-better method
  2. How To Browse Windows Shares

OK, we live in the wonderful world of Linux. BUT, for many of us, having to deal with Windows is a fact of life. For example, you may want to use a Linux server to back up Windows files. This can be made easy by mounting Windows shares on the server. You will be accessing Windows files as if they are local and essentially all Linux commands can be used. Mounting Windows (or other samba) shares is done through the cifs virtual file system client (cifs vfs) implemented in kernel and a mount helper mount.cifs which is part of the samba suite.

The following names are used in our examples.

remote Windows machine 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.

You may want to use different options for cifs. For example, nocase allows case insensitive path name matching. Do a man mount.cifs to see more options.

[Note: if you used smbfs in earlier versions of CentOS, you must replace it with cifs in CentOS 5 because smbfs has been deprecated.]

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 the remote share 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

[Note: 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.

[More note: If you cannot connect by the machine name but can connect by its IP address, then add wins on the hosts line of /etc/nsswitch.conf .]

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.

[Note: Upon automounting, you may see an error mount_cifs.so: cannot open shared object file in /var/log/messages. This is harmless and can be safely ignored.]

Congratulations! You‘re done.


  • <!> Note for CentOS 5.0 and CentOS 4.5 users.

There is a bug in the cifs filesystem module of kernel 2.6.18 that CentOS 5.0 (RHEL 5.0) uses. CentOS 4.5 now uses the same version of cifs. 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 (cifs.ko) for CentOS 5.0. Please see the following bug report for more details.

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

CentOS 4.5 users might want to try test kernels with the patch offered by upstream. See the bug report.


How To Browse Windows Shares

If you just want 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/getme

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

TipsAndTricks/WindowsShares (2007-07-04 22:34:31由AkemiYagi编辑)

 
 
 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多