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, 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

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 are managing a multiuser system, consider setting the dir_mode and file_mode options to your mount point.

1. Required packages

Make sure that the following packages are installed:

[root@host]# yum install samba-client samba-common cifs-utils

which will also pull in any needed dependencies. Note that cifs-utils is for CentOS-6 (or later) only.

2. Basic method

Create a local mount point. For example:

[root@host]# 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, local user (uid=500) will become the owner of the mounted files. Use of the uid flag is optional. However, it may be required for certain applications (for example, Acrobat) to work because they are picky about the permissions.

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.]

3. 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

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=sushi
password=yummy

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

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

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

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

[root@host]# 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 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.mymount 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 .]

When all is 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 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.]

5. Yet Another Even-better method

If you have multiple shares to mount with the same credentials, there is a handy way to set it up.

Create a local mountpoint (of your choice):

[root@host]# 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 that the permission bits are correct and restart the service:

[root@host]# chmod 644 /etc/auto.smb.*
[root@host]# /sbin/service autofs restart

Now you can access by simply typing:

[user@host]$ cd /mnt/smb/winbox/getme

(Thanks to Mia Via for sending in this tip)

Additional tips:

If you have multiple remote 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 man page for details about 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 that CentOS 5.0 (RHEL 5.0) and CentOS 4.5 (RHEL 4.5) use. This bug causes kernel oopses or system crashes in an unpredictable manner. Please see the bug report for more details: http://bugs.centos.org/view.php?id=1776

  • Note added: The bug was 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 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).

How to mount remote Windows shares的更多相关文章

  1. How To mount/Browse Windows Shares【在linux{centos}上挂载、浏览window共享】

    How to mount remote Windows shares Contents Required packages Basic method Better Method Even-better ...

  2. How to mount remote windows partition (windows share) under Linux

    http://www.cyberciti.biz/tips/how-to-mount-remote-windows-partition-windows-share-under-linux.html  ...

  3. Mac:How to mount a Windows shared folder

    Reference: How to mount a Windows shared folder on your Mac

  4. Linux上mount 挂载windows共享文件权限问题

    在服务器部署的时候需要把文件夹设置在windows的共享文件上.在使用mount命令挂载到linux上后.文件路径和文件都是可以访问,但是不能写入,导致系统在上传文件的时候提示“权限不够,没有写权限” ...

  5. mount挂载WINDOWS分区和目录

    转自:http://blog.163.com/sg_liao/blog/static/29577083200942811445981/ 一,挂载共享目录 sudo mount -t cifs  -o ...

  6. Linux使用mount挂载Windows共享文件夹

    https://blog.csdn.net/tojohnonly/article/details/71374984 https://github.com/tojohnonly 现实中会有这样的场景 , ...

  7. MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption 2017-05-18 16:45

    wget "https://raw.githubusercontent.com/rapid7/metasploit-framework/6d81ca42087efd6548bfcf92417 ...

  8. mount.cifs Windows共享目录权限755问题

    umount -l /usr/local/tomcat7/webapps/dsideal_yy/html/down mount -t cifs -o rw,dir_mode=,file_mode=,s ...

  9. 校园网跨网段共享文件Samba+SSH

    Introduction This tutorial contains screenshots for the English version of Windows 10. Separate inst ...

随机推荐

  1. Array.ConvertAll<TInput, TOutput> 数组相互转化方法

    有个需求,把char数组转换为int数组,然后噼里啪啦就弄了这样一堆代码: public static int[] CharArrToIntArr(char[] charArr) { int[] in ...

  2. web页面找不到资源文件,报404,但是资源文件存在且路径没错

    如题 , 今天遇到这个问题,maven项目导入本地myeclipse,正常跑起来之后,在web端存在部分页面资源加载不进来. 但是项目资源确实存在,一开始以为是myeclipse开发环境搭建错误导致, ...

  3. 企业证书发布app到七牛云服务

    ---恢复内容开始--- 最近在做企业证书发布app,从申请企业证书,到测试程序发布到七牛云存储.整了几天终于实现了,整理一下资料. 1.首先,申请企业证书. 到苹果开发网站申请企业证书 https: ...

  4. eclipse 建立Maven java工程

    1.在项目资源管理器右键---新建---项目 2.在选择向导里选择Maven---Maven Project 3.选择默认的工作空间,下一步 4.选择箭头所示选项 5.输入组织名和工程名.点击完成

  5. HBASE概念补充

    HBASE概念补充 HBase的工作方式: hbase中的表在行的方向上分隔为多个HRegion,分散在不同的RegionServer中 这样做的目的是在查询时可以将工作量分布到多个RegionSer ...

  6. 论文阅读 | Text Processing Like Humans Do: Visually Attacking and Shielding NLP Systems

    [code&data] [pdf] 主要工作 文章首先证明了对抗攻击对NLP系统的影响力,然后提出了三种屏蔽方法: visual character embeddings adversaria ...

  7. 7.编写mapreduce案例

    在写一个mapreduce类之前先添加依赖包 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&qu ...

  8. mysql语句(一)

    --建表CREATE TABLE IF NOT EXISTS `runoob_tbl`( `runoob_id` INT UNSIGNED AUTO_INCREMENT, `runoob_title` ...

  9. 【LOJ】#3033. 「JOISC 2019 Day2」两个天线

    LOJ#3033. 「JOISC 2019 Day2」两个天线 用后面的天线更新前面的天线,线段树上存历史版本的最大值 也就是线段树需要维护历史版本的最大值,后面的天线的标记中最大的那个和最小的那个, ...

  10. Arthas查看Spring配置

    在开发过程经常有同学问:"我这个配置更新提交了,怎么样知道项目中是否已经更新使用新值?" 常用的方法是添加日志打印该值判断是否更新.今天我们用Arthas来实现项目中配置值实时读取 ...