How to mount remote Windows shares

来源:百度文库 编辑:神马文学网 时间:2024/04/28 15:57:20
CentOS 5.0 and CentOS 4.5 users. Please readthis important note
How to mount remote Windows sharesBasic methodBetter MethodEven-better method
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/winEdit 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 0The 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 0And the /root/secret.txt file looks like this:
username=sushipassword=yummyThis 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/getmeOr by using the same credentials file as above:
winbox -fstype=cifs,rw,noperm,credentials=/root/secret.txt ://winbox/getmeNote 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.centos.org/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/getmeIf you use nautilus, type a / first (thanks toJohnnyHughes for this hint).
TipsAndTricks/WindowsShares (2007-07-04 22:34:31由AkemiYagi编辑)
from: http://wiki.centos.org/TipsAndTricks/WindowsShares