How to mount remote 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

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


Written and currently maintained by AkemiYagi. Corrections/suggestions welcome.

How To mount/Browse Windows Shares【在linux{centos}上挂载、浏览window共享】的更多相关文章

  1. How to mount remote Windows shares

      Contents Required packages Basic method Better Method Even-better method Yet Another Even-better m ...

  2. NoSql1 在Linux(CentOS)上安装memcached及使用

    前言:       今天是初五,生活基本要从过年的节奏中回归到正常的生活了,所以想想也该想想与工作有关的事情了.我之前在工作中会经常使用memcached和redis,但是自己一直没有时间系统的好好看 ...

  3. 如何在linux CentOS 上安装chrome 谷歌浏览器?

    获得linux命令的root权限:http://blog.csdn.net/mddy2001/article/details/76521101. 更改密码在终端中输入:sudo passwd root ...

  4. Windows服务器从Linux服务器上以FTP形式获取图片

    Windows服务器上运行一个获取图片的程序,获取图片采用的是FTP方式: 准备条件: Linux服务器上创建一个FTP的用户:ftppic 这个账号要有权限才可以,然后编写Windows端代码: p ...

  5. 在Linux CentOS上搭建Jmeter压测环境

    本文的主要内容是介绍如何在Linux CentOS 服务器上面搭建Jmeter的压测环境整个详细的流程,来满足我们日常工作中对于压力测试环境搭建.压力测试执行过程的需求. 一.首先我们要准备四个东西, ...

  6. Linux~centos上安装.netcore,HelloWorld归来!

    对于跨平台的.netCore来说,让它的程序运行在Linux系统上已经成为必然,也是一种趋势,毕竟我们的很多服务都放在linux服务器上(redis,mongodb,myql,fastDFS,luce ...

  7. 在Linux CentOS上编译并安装Clang 3.5.0

    编译CoreCLR需要Clang 3.5,而CentOS上安装的是Clang 3.4.2(yum repos中最新版也是这个),只能自己手工编译LLVM的源代码进行安装. (注:CentOS的版本是6 ...

  8. 在Linux CentOS上部署Asp.Net Core项目(Tengine、Asp.Net Core、Centos、MySql)

    一.前言 1.简单记录一下Linux CentOS 7中安装与配置Tengine的详细步骤. 2.简单比较一下Tengine 和Nginx 3.搭建Asp.net Core和部署 Web程序 4.总结 ...

  9. Linux CentOS上安装 MySQL 8.0.16

    前言: 因为我需要在我新安装的Linux CentOS系统服务器中安装和配置MySQL服务器,然而对于我们这种Linux使用小白而言在Linux系统中下载,解压,配置MySQL等一系列的操作还是有些耗 ...

随机推荐

  1. 跟着百度学PHP[7]会话控制(session与cookie) 1.cookie的设置

    参考慕课网:http://www.imooc.com/learn/26 参考W3C:http://www.w3school.com.cn/php/php_cookies.asp setcookie() ...

  2. 【Android - 基础】之PopupWindow的使用

    创建一个类继承自PopupWindow,编写自定义的PopupWindow类.示例代码如下: import android.app.Activity; import android.graphics. ...

  3. 苹果电脑出现 .DS_Store文件,删除不掉怎么处理?

    今天早上打开电脑,发现桌面上出现一个.DS_Store文件.可是出现的莫名其妙,也就没在意,可是重复删除之后还是出现.后来查了一下网上的资料,才知道,昨天我加入git的时候,为了看见 .git这个隐藏 ...

  4. Linux下Wireshark普通用户不能获取网络接口问题

    Linux下Wireshark普通用户不能获取网络接口问题 1.安装setcap, setcap 是libcap2-bin包的一部分,一般来说,这个包默认会已经装好. sudo apt-get ins ...

  5. 深度剖析:CDN内容分发网络技术原理--转载

    1.前言 Internet的高速发展,给人们的工作和生活带来了极大的便利,对Internet的服务品质和访问速度要求越来越高,虽然带宽不断增加,用户数量也在不断增加,受Web服务器的负荷和传输距离等因 ...

  6. oracle在敏感操作前创建还原点

    我们都知道,在vmware虚拟机中有一个拍摄快照的功能,我们可以把系统此时的状态保存下来,一方后面遇到不测事件,也好将系统还原,oracle中也有类似功能. 首先创建一张学生表: 向学生表中插入一条数 ...

  7. 如何让Windows程序只运行一个程序实例?

    要实现VC++或者MFC只运行一个程序实例,一般采用互斥量来实现,即首先用互斥量封装一个只运行一个程序实例的函数接口: HANDLE hMutex = NULL; void MainDlg::RunS ...

  8. iOS UIKit:TableView之单元格配置(2)

    Table View是UITableView类的实例对象,其是使用节(section)来描述信息的一种滚动列表.但与普通的表格不同,tableView只有一行,且只能在垂直方向进行滚动.tableVi ...

  9. Bash判断文件夹(目录)是否存在

    #!/bin/bash if [ -d DirName ]; then echo 'Dir exist' else echo 'Dir not exist' fi

  10. 如何让android sdk manager飞奔安装sdk

    由于国内的gwf的原因,凡是google的服务都是无法正常访问,这两天从android官网上下载sdk不是一般的慢.不过现在有一个好的方法.sdk都是从https://dl-ssl.google.co ...