共享 Windows 磁盘给 Linux 机器

本文介绍了共享Windows磁盘给Linux机器的方法。Samba发行套件中的SMB client程序可实现此功能,文中给出查看主机共享资源、连接共享目录的命令示例,还展示了使用smbclient获取共享文件夹中文件的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

共享 Windows 磁盘给 Linux 机器
一种给 UNIX 机器用的 SMB client 程序被包含在 Samba 发行套件之中.它提供一种在命令列下的像ftp的界面.

想要看在给定的主机上有哪些共享可取得, 执行:

--------------------------------------------------------------------------------

    /usr/sbin/smbclient -L host


--------------------------------------------------------------------------------

这里的 'host' 是你想要浏览的机器名子. 这将会响应一串 'service' 的域名 - 也就是, 它所共享给你的磁盘或打印机的域名. 除非 SMB 服务器没有安全上的设定, 否则它将要求你输入密码. 给它 'guest' 帐号的密码或是你个人在那台机器上帐号的密码.

举个例子:

--------------------------------------------------------------------------------

    smbclient -L zimmerman


--------------------------------------------------------------------------------

这个指令的输出应该看起来像是这样:

--------------------------------------------------------------------------------

Server time is Sat Aug 10 15:58:27 1996
Timezone is UTC+10.0
Password:
Domain=[WORKGROUP] OS=[Windows NT 3.51] Server=[NT LAN Manager 3.51]

Server=[ZIMMERMAN] User=[] Workgroup=[WORKGROUP] Domain=[]

        Sharename      Type      Comment
        ---------      ----      -------
        ADMIN$         Disk      Remote Admin
        public         Disk      Public
        C$             Disk      Default share
        IPC$           IPC       Remote IPC
        OReilly        Printer   OReilly
        print$         Disk      Printer Drivers


This machine has a browse list:

        Server               Comment
        ---------            -------
        HOPPER               Samba 1.9.15p8
        KERNIGAN             Samba 1.9.15p8
        LOVELACE             Samba 1.9.15p8
        RITCHIE              Samba 1.9.15p8
        ZIMMERMAN           


--------------------------------------------------------------------------------

这个 browse list 列出其它有资源共享给网络的 SMB 服务器.

要使用此 client, 请执行:

--------------------------------------------------------------------------------

    /usr/sbin/smbclient service <password>


--------------------------------------------------------------------------------

这里的 'service' 是一台机器和共享域名. 举例而言,如果你设法连到一台叫做 zimmerman 的机器上之以 'public' 为共享域名的目录 ,此 service 要叫做 //zimmerman/public. 然而,因为 shell 限制, 你会需要脱离 backslashes, 所以你要像这样的结束:

--------------------------------------------------------------------------------

    /usr/sbin/smbclient ////zimmerman//public mypasswd


--------------------------------------------------------------------------------

这样的 'mypasswd' 是你的密码之文字串{literal string}.

你将会有 smbclient 的提示符号{prompt}出现:

--------------------------------------------------------------------------------

Server time is Sat Aug 10 15:58:44 1996
Timezone is UTC+10.0
Domain=[WORKGROUP] OS=[Windows NT 3.51] Server=[NT LAN Manager 3.51]
smb: />


--------------------------------------------------------------------------------

键入 'h' 取得关于使用 smbclient 的 help:

--------------------------------------------------------------------------------

smb: /> h
ls             dir            lcd            cd             pwd           
get            mget           put            mput           rename        
more           mask           del            rm             mkdir         
md             rmdir          rd             prompt         recurse       
translate      lowercase      print          printmode      queue         
cancel         stat           quit           q              exit          
newer          archive        tar            blocksize      tarmode       
setmode        help           ?              !             
smb: />


--------------------------------------------------------------------------------

如果你能使用ftp,你应该不需要查询 smbclient 的 man pages.

下面是通过grape上访问我的机器里面的共享文件夹。 并获得两个文件的过程。

[hanhj@grape hanhj]$ smbclient -L hanhj
added interface ip=211.71.6.247 bcast=211.71.6.255 nmask=255.255.255.192
Got a positive name query response from 211.71.6.215 ( 211.71.6.215 )
Password:
Domain=[WORKGROUP] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]

        Sharename      Type      Comment
        ---------      ----      -------
        E$             Disk      默认共享
        IPC$           IPC       远程 IPC
        D$             Disk      默认共享
        Debug          Disk
        G$             Disk      默认共享
        F$             Disk      默认共享
        ADMIN$         Disk      远程管理
        C$             Disk      默认共享

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------
[hanhj@grape hanhj]$ smbclient ////hanhj/Debug
added interface ip=211.71.6.247 bcast=211.71.6.255 nmask=255.255.255.192
Usage: smbclient service <password> [options]
Version 2.2.7a
        -s smb.conf           pathname to smb.conf file
        -O socket_options     socket options to use
        -R name resolve order use these name resolution services only
        -M host               send a winpopup message to the host
        -i scope              use this NetBIOS scope
        -N                    don't ask for a password
        -n netbios name.      Use this name as my netbios name
        -d debuglevel         set the debuglevel
        -P                    connect to service as a printer
        -p port               connect to the specified port
        -l log basename.      Basename for log/debug files
        -h                    Print this help message.
        -I dest IP            use this IP to connect to
        -E                    write messages to stderr instead of stdout
        -U username           set the network username
        -L host               get a list of shares available on a host
        -t terminal code      terminal i/o code {sjis|euc|jis7|jis8|junet|hex}
        -m max protocol       set the max protocol level
        -A filename           get the credentials from a file
        -W workgroup          set the workgroup name
        -T<c|x>IXFqgbNan      command line tar
        -D directory          start from directory
        -c command string     execute semicolon separated commands
        -b xmit/send buffer   changes the transmit/send buffer (default: 65520)


//hanhjDebug: Not enough '/' characters in service
[hanhj@grape hanhj]$ smbclient ////hanhj//Debug
added interface ip=211.71.6.247 bcast=211.71.6.255 nmask=255.255.255.192
Got a positive name query response from 211.71.6.215 ( 211.71.6.215 )
Password:
Domain=[WORKGROUP] OS=[Windows 5.1] Server=[Windows 2000 LAN Manager]
smb: /> help
?              altname        archive        blocksize      cancel
cd             chmod          chown          del            dir
du             exit           get            help           history
lcd            link           lowercase      ls             mask
md             mget           mkdir          more           mput
newer          open           print          printmode      prompt
put            pwd            q              queue          quit
rd             recurse        rename         rm             rmdir
setmode        symlink        tar            tarmode        translate
!
smb: /> ls
  .                                   D        0  Fri Mar 25 18:08:54 2005
  ..                                  D        0  Fri Mar 25 18:08:54 2005
  vc60.idb                            A   156672  Fri Mar 25 18:07:08 2005
  vc60.pdb                            A   102400  Mon Jan 10 23:35:04 2005
  WinMsgDll.bsc                       A  1991680  Mon Jan 10 23:35:04 2005
  WinMsgDll.dll                       A   204854  Mon Jan 10 23:35:04 2005
  WinMsgDll.exp                       A      746  Tue Jan  4 23:58:02 2005
  WinMsgDll.ilk                       A   261308  Mon Jan 10 23:35:04 2005
  WinMsgDll.lib                       A     2094  Tue Jan  4 23:58:02 2005
  WinMsgDLL.obj                       A    13124  Mon Jan 10 23:35:04 2005
  WinMsgDll.pch                       A  4714204  Mon Jan 10 23:35:04 2005
  WinMsgDll.pdb                       A   631808  Mon Jan 10 23:35:04 2005
  WinMsgDLL.sbr                       A        0  Mon Jan 10 23:35:04 2005

                59934 blocks of size 262144. 8213 blocks available
smb: /> help get
HELP get:
        <remote name> [local name] get a file

smb: /> get vc60.pdb
getting file /vc60.pdb of size 102400 as vc60.pdb (2222.2 kb/s) (average 2222.2 kb/s)
smb: />
smb: /> get *.lib
NT_STATUS_OBJECT_NAME_INVALID opening remote file /*.lib
smb: /> get WinMsgDll.lib
getting file /WinMsgDll.lib of size 2094 as WinMsgDll.lib (681.6 kb/s) (average 2125.9 kb/s)
smb: />q
[hanhj@grape hanhj]$

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值