How to mount remote Windows shares

Source: Internet
Author: User
Tags winbox

Contents

    1. Required Packages
    2. Basic method
    3. Better Method
    4. Even-better method
    5. Yet another Even-better method

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

The following names is used in our examples.

    • Remote Windows machine Winbox
      Share name on Winbox: getme
      Username: Sushi
      Password: yummy

Word of warning:the default behaviour for Mount.cifs is leaving the mounted share unsecured (Http://bugs.centos.org/view. php?id=4537). If You is managing a multiuser system, consider setting the dir_mode and file_mode options to your Moun T point.

1. Required Packages

Make sure, the following packages is installed:

[Email protected]]# yum install samba-client Samba-common cifs-utils

Which'll also pull in any needed dependencies. Note that cifs-utils are for CentOS-6 (or later) only.

2. Basic method

Create a local mount point. For example:

[[Email protected]]# Mkdir/mnt/win

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

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

The Windows share gets mounted on boot. Add the noauto option if you wish to manually mount it by the command Mount/mnt/win . In this example, the local user (uid=500) is become the owner of the mounted files. Use of the UID, flag is optional. However, it may is required for certain applications (for example, Acrobat) to work because they is picky about the Permi Ssions.

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 used SMBFS in earlier versions of the CentOS, you must replace it with cifs in CentOS 5 becaus E smbfs has been deprecated.]

3. Better Method

The above method has a little problem. Username and password is 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

Note:per Jbroome, in IRC, a working example looks like this

\\jellyfish\dbrefreshlogs\beta2/media/dbrefreshlogs/beta2 CIFS    credentials=/root/secret.txt,_netdev,uid= ORACLE,GID=DBA 0 0

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

Username=sushipassword=yummy

This file can be placed anywhere. Encrypted passwords cannot be used. Make sure it isn't readable by others. Note also that no spaces is allowed.

(Note:username can have a form of username=<domain>/)

4. 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 is connecting to might crash (surprise!) or the network might go down.

AutoMount comes in handy (if you don ' t already has autofs, install it by yum install AutoFS). Here's what's need to do. First create a mount point

[[Email protected]]# mkdir/mymount

[Note:you can use any directory, make sure, that directory exists]

To the /etc/auto.master file add a line like:

/mymount/etc/auto.mymount

Then edit the /etc/auto.mymount file 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.mymount can was made world-unreadable, so, use of the credentials file are not as Impo Rtant as in the previous method.

[More Note:if your cannot connect by the machine name but can connect by its IP address and then add wins on the hosts Line of /etc/nsswitch.conf .]

When all are ready, run /sbin/service autofs restart as root.

Now try accessing the share by Ls/mymount/winbox or by Cd/mymount/winbox . It is dynamically loaded upon access. After some inactivity (default seconds), the share would be unmounted.

[Note:upon automounting, you could see a error Mount_cifs.so:cannot open Shared object file in /var/log/mess Ages. This is harmless and can safely ignored.]

5. Yet another Even-better method

If you had multiple shares to mount with the same credentials, the There is a handy-to set it up.

Create a local mountpoint (of your choice):

[[Email protected]]# MKDIR/MNT/SMB

Add this line to /etc/auto.master:

/mnt/smb/etc/auto.smb.top

Create /etc/auto.smb.top as:

*-fstype=autofs,-dhost=& File:/etc/auto.smb.sub

Create /etc/auto.smb.sub as (adjust as needed):

*-fstype=cifs,credentials=/root/secret.txt,uid=500,gid=100://${host}/&

Let's make sure, the permission bits is correct and restart the service:

[Email protected]]# chmod 644/etc/auto.smb.*[[email protected]]#/sbin/service autofs Restart

Now you can access by simply typing:

[[Email protected]]$ cd/mnt/smb/winbox/getme

(Thanks to Mia Via for sending in this tip)

Additional tips:

If you have multiple remotes servers and shares with different usernames and/or passwords, use this formula:

*-fstype=cifs,credentials=/root/${host}.secret.txt,uid=${uid},gid=${euid}://${host}/&

To allow users to put their own usernames/passwords to their home directories (might expose security even more):

*-fstype=cifs,credentials=${home}/${host}.secret.txt,uid=${uid},gid=${euid}://${host}/&

To improve security with samba-servers, you could also add sec=ntlmv2, and make credentials file hidden like this:

*-fstype=cifs,sec=ntlmv2,credentials=${home}/.${host}.secret.txt,uid=${uid},gid=${euid}://${host}/&

See Mount.cifs Mans page for details on the Sec-and other CIFS related mount parameters.

(Thanks to Tapio Ryh?nen for sending in these tips)

Note for CentOS 5.0 and CentOS 4.5 users. There is a bug in the CIFS filesystem module of kernel 2.6.18, CentOS 5.0 (Rhel 5.0) and CentOS 4.5 (Rhel 4.5) use. This bug is causes kernel oopses or system crashes in an unpredictable manner. Please see the bug in report for more details:http://bugs.centos.org/view.php?id=1776

    • Note added:the Bug is fixed in CentOS 5.1 (kernel-2.6.18-53) and 4.6 (kernel-2.6.9-67).

How to Browse Windows Shares

If you just want-to-browse Windows files, you don't need to mount them. There is easy ways to access them from your file browser.

In Konqueror, Go-Network folders, Samba Shares
In Nautilus, Places-and network-Windows network

To go-a specific share more quickly, you can type directly in the Location box of Konqueror:

Smb://winbox/getme

If Nautilus, type a / first (thanks to johnnyhughes for this hint).

How to mount remote Windows shares

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.