IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Linux访问MS Windows共享文件路径

    Adamhuan发表于 2016-11-04 07:03:20
    love 0

    需求很明确,如题所示,系统通过Linux访问由MS Windows共享的一个路径。

    在接下来的环境中,我的MS Windows共享目录为:
    linux_mswin_shared_1

    该共享路径的权限设置如下:
    linux_mswin_shared_2

    准备好了环境,接下来是【Linux】端的事情了。

    开始:
    挂载光盘:

    [root@center-me ~]# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda3        46G   11G   33G  24% /
    tmpfs           1.9G   72K  1.9G   1% /dev/shm
    /dev/sda1       283M   39M  229M  15% /boot
    [root@center-me ~]# 
    [root@center-me ~]# 
    [root@center-me ~]# mount /dev/sr0 /iso
    mount: block device /dev/sr0 is write-protected, mounting read-only
    [root@center-me ~]# 
    [root@center-me ~]# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda3        46G   11G   33G  24% /
    tmpfs           1.9G   72K  1.9G   1% /dev/shm
    /dev/sda1       283M   39M  229M  15% /boot
    /dev/sr0        3.7G  3.7G     0 100% /iso
    [root@center-me ~]#

    查找,是否安装了SAMBA有关的程序包:

    [root@center-me ~]# rpm -qa | grep --color samba
    samba-winbind-clients-3.6.23-33.el6.x86_64
    samba-winbind-3.6.23-33.el6.x86_64
    samba-common-3.6.23-33.el6.x86_64
    [root@center-me ~]# 
    [root@center-me ~]# yum list | grep --color ^samba
    samba-common.x86_64                            3.6.23-33.el6                @anaconda-CentOS-201605220104.x86_64/6.8
    samba-winbind.x86_64                           3.6.23-33.el6                @anaconda-CentOS-201605220104.x86_64/6.8
    samba-winbind-clients.x86_64                   3.6.23-33.el6                @anaconda-CentOS-201605220104.x86_64/6.8
    samba.x86_64                                   3.6.23-33.el6                ISO 
    samba-client.x86_64                            3.6.23-33.el6                ISO 
    samba-common.i686                              3.6.23-33.el6                ISO 
    samba-doc.x86_64                               3.6.23-33.el6                ISO 
    samba-domainjoin-gui.x86_64                    3.6.23-33.el6                ISO 
    samba-glusterfs.x86_64                         3.6.23-33.el6                ISO 
    samba-swat.x86_64                              3.6.23-33.el6                ISO 
    samba-winbind-clients.i686                     3.6.23-33.el6                ISO 
    samba-winbind-devel.i686                       3.6.23-33.el6                ISO 
    samba-winbind-devel.x86_64                     3.6.23-33.el6                ISO 
    samba-winbind-krb5-locator.x86_64              3.6.23-33.el6                ISO 
    samba4.x86_64                                  4.2.10-6.el6_7               ISO 
    samba4-client.x86_64                           4.2.10-6.el6_7               ISO 
    samba4-common.x86_64                           4.2.10-6.el6_7               ISO 
    samba4-dc.x86_64                               4.2.10-6.el6_7               ISO 
    samba4-dc-libs.x86_64                          4.2.10-6.el6_7               ISO 
    samba4-devel.x86_64                            4.2.10-6.el6_7               ISO 
    samba4-libs.x86_64                             4.2.10-6.el6_7               ISO 
    samba4-pidl.x86_64                             4.2.10-6.el6_7               ISO 
    samba4-python.x86_64                           4.2.10-6.el6_7               ISO 
    samba4-test.x86_64                             4.2.10-6.el6_7               ISO 
    samba4-winbind.x86_64                          4.2.10-6.el6_7               ISO 
    samba4-winbind-clients.x86_64                  4.2.10-6.el6_7               ISO 
    samba4-winbind-krb5-locator.x86_64             4.2.10-6.el6_7               ISO 
    [root@center-me ~]#

    安装SAMBA-CLIENT:

    [root@center-me ~]# yum info samba-client
    Loaded plugins: fastestmirror, refresh-packagekit, security
    Loading mirror speeds from cached hostfile
     * epel: mirror.premi.st
    Installed Packages
    Name        : samba-client
    Arch        : x86_64
    Version     : 3.6.23
    Release     : 33.el6
    Size        : 40 M
    Repo        : installed
    From repo   : ISO
    Summary     : Samba client programs
    URL         : http://www.samba.org/
    License     : GPLv3+ and LGPLv3+
    Description : The samba-client package provides some SMB/CIFS clients to complement
                : the built-in SMB/CIFS filesystem in Linux. These clients allow access
                : of SMB/CIFS shares and printing to SMB/CIFS printers.
    
    [root@center-me ~]# 
    [root@center-me ~]# yum install -y samba-client
    Loaded plugins: fastestmirror, refresh-packagekit, security
    Setting up Install Process
    Loading mirror speeds from cached hostfile
     * epel: mirror.premi.st
    Resolving Dependencies
    --> Running transaction check
    ---> Package samba-client.x86_64 0:3.6.23-33.el6 will be installed
    --> Finished Dependency Resolution
    
    Dependencies Resolved
    
    ==========================================================================================================================
     Package                         Arch                      Version                           Repository              Size
    ==========================================================================================================================
    Installing:
     samba-client                    x86_64                    3.6.23-33.el6                     ISO                     11 M
    
    Transaction Summary
    ==========================================================================================================================
    Install       1 Package(s)
    
    Total download size: 11 M
    Installed size: 40 M
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing : samba-client-3.6.23-33.el6.x86_64                                                                      1/1 
      Verifying  : samba-client-3.6.23-33.el6.x86_64                                                                      1/1 
    
    Installed:
      samba-client.x86_64 0:3.6.23-33.el6                                                                                     
    
    Complete!
    [root@center-me ~]# 
    [root@center-me ~]# yum list | grep --color samba | grep --color client
    samba-client.x86_64                            3.6.23-33.el6                @ISO
    samba-winbind-clients.x86_64                   3.6.23-33.el6                @anaconda-CentOS-201605220104.x86_64/6.8
    samba-winbind-clients.i686                     3.6.23-33.el6                ISO 
    samba4-client.x86_64                           4.2.10-6.el6_7               ISO 
    samba4-winbind-clients.x86_64                  4.2.10-6.el6_7               ISO 
    [root@center-me ~]#
    [root@center-me ~]# rpm -qa | grep --color samba
    samba-winbind-clients-3.6.23-33.el6.x86_64
    samba-winbind-3.6.23-33.el6.x86_64
    samba-client-3.6.23-33.el6.x86_64
    samba-common-3.6.23-33.el6.x86_64
    [root@center-me ~]#

    这样,就安装好了。

    下面开始使用:
    从Linux中查看MS Windows中共享了哪些目录:

    [root@center-me ~]# smbclient -L 192.168.111.1 -U ******
    Enter ******'s password: 
    Domain=[DESKTOP-C9B7MJA] OS=[Windows 10 Pro 14393] Server=[Windows 10 Pro 6.3]
    
            Sharename       Type      Comment
            ---------       ----      -------
            ADMIN$          Disk      远程管理
            C$              Disk      默认共享
            D$              Disk      默认共享
            G$              Disk      默认共享
            IPC$            IPC       远程 IPC
            shared_me       Disk      
    session request to 192.168.111.1 failed (Called name not present)
    session request to 192 failed (Called name not present)
    session request to *SMBSERVER failed (Called name not present)
    NetBIOS over TCP disabled -- no workgroup available
    [root@center-me ~]#

    可以看到我们刚才共享出来的地址:shared_me。

    在Linux中挂载:

    [root@center-me ~]# df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/sda3        46G   11G   33G  24% /
    tmpfs           1.9G   72K  1.9G   1% /dev/shm
    /dev/sda1       283M   39M  229M  15% /boot
    /dev/sr0        3.7G  3.7G     0 100% /iso
    [root@center-me ~]# 
    [root@center-me ~]# mount -t cifs -o username=******,password=****** //192.168.111.1/shared_me /mnt_mswin/
    [root@center-me ~]# 
    [root@center-me ~]# df -h
    Filesystem            Size  Used Avail Use% Mounted on
    /dev/sda3              46G   11G   33G  24% /
    tmpfs                 1.9G   72K  1.9G   1% /dev/shm
    /dev/sda1             283M   39M  229M  15% /boot
    /dev/sr0              3.7G  3.7G     0 100% /iso
    //192.168.111.1/shared_me
                          466G  167G  300G  36% /mnt_mswin
    [root@center-me ~]#

    访问:

    [root@center-me ~]# cd /mnt_mswin/
    [root@center-me mnt_mswin]# ls -ltr --time-style="+|%Y-%m-%d|%H:%M:%S|"
    total 1
    -rwxr-xr-x 0 root root 28 |2016-11-03|23:59:23| i_am_here.txt
    [root@center-me mnt_mswin]# 
    [root@center-me mnt_mswin]# cat i_am_here.txt 
    Now you see me. - Jay Chow
    
    [root@center-me mnt_mswin]#

    向其中写点内容:

    [root@center-me mnt_mswin]# touch me
    [root@center-me mnt_mswin]# ls -ltr --time-style="+|%Y-%m-%d|%H:%M:%S|"
    total 1
    -rwxr-xr-x 0 root root 28 |2016-11-03|23:59:23| i_am_here.txt
    -rwxr-xr-x 0 root root  0 |2016-11-04|00:00:09| me
    [root@center-me mnt_mswin]# 
    [root@center-me mnt_mswin]# echo "I'm here, where are you?" > me
    [root@center-me mnt_mswin]# 
    [root@center-me mnt_mswin]# cat me 
    I'm here, where are you?
    [root@center-me mnt_mswin]#

    然后,去MS Windows查看:
    linux_mswin_shared_3

    ————————————————————
    Done。



沪ICP备19023445号-2号
友情链接