smbclient 是一个可以连接到 SMB/CIFS 服务器的客户端。它提供了一个类似于ftp程序的接口,详见 ftp(1)。操作包括从服务器获取文件到本地机器,将文件从本地机器放入服务器,从服务器检索目录信息等等。
简介
smbclient [-b
] [-d debuglevel] [-e] [-L ] [-U username] [-I destinationIP]
[-M] [-m maxprotocol] [-A authfile] [-N] [-C] [-g] [-i scope] [-O ]
[-p port] [-R] [-s ] [-t ]
[-k] [-P] [-c] smbclient {servicename} [password] [-b
] [-d debuglevel] [-e] [-D Directory] [-U username]
[-W workgroup] [-M] [-m maxprotocol] [-A authfile] [-N] [-C] [-g] [-l log-basename]
[-I destinationIP] [-E] [-c] [-i scope] [-O ] [-p port]
[-R] [-s ] [-t ] [-T<c|x>IXFqgbNan] [-k]
描述
- 此工具是 samba(7) 套件的一部分
- smbclient 是一个可以连接到 SMB/CIFS 服务器的客户端。它提供了一个类似于ftp程序的接口,详见 ftp(1)。操作包括从服务器获取文件到本地机器,将文件从本地机器放入服务器,从服务器检索目录信息等等。
- Common Internet File System(常见网络文件系统).CIFS 使用客户/服务器模式。客户程序请求远在服务器上的服务器程序为它提供服务。服务器获得请求并返回响应。CIFS是公共的或开放的SMB协议版本,并由Microsoft使用。
选项
-B<ip地址>:传送广播数据包时所用的IP地址;
-d<排错层级>:指定记录文件所记载事件的详细程度;
-E:将信息送到标准错误输出设备;
-h:显示帮助;
-i<范围>:设置NetBIOS名称范围;
-I<IP地址>:指定服务器的IP地址;
-l<记录文件>:指定记录文件的名称;
-L:显示服务器端所分享出来的所有资源;
-M<NetBIOS名称>:可利用WinPopup协议,将信息送给选项中所指定的主机;
-n<NetBIOS名称>:指定用户端所要使用的NetBIOS名称;
-N:不用询问密码;
-O<连接槽选项>:设置用户端TCP连接槽的选项;
-p<TCP连接端口>:指定服务器端TCP连接端口编号;
-R<名称解析顺序>:设置NetBIOS名称解析的顺序;
-s<目录>:指定smb.conf所在的目录;
-t<服务器字码>:设置用何种字符码来解析服务器端的文件名称;
-T<tar选项>:备份服务器端分享的全部文件,并打包成tar格式的文件;
-U<用户名称>:指定用户名称;
-w<工作群组>:指定工作群组名称。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
用法: smbclient service <password> -R, --name-resolve=NAME-RESOLVE-ORDER Use these name resolution services only -M, --message=HOST Send message -I, --ip-address=IP Use this IP to connect to -E, --stderr Write messages to stderr instead of stdout -L, --list=HOST Get a list of shares available on a host -m, --max-protocol=LEVEL Set the max protocol level -T, --tar=<c|x>IXFqgbNan Command line tar -D, --directory=DIR Start from directory -c, --command=STRING Execute semicolon separated commands -b, --send-buffer=BYTES Changes the transmit/send buffer -t, --timeout=SECONDS Changes the per-operation timeout -p, --port=PORT Port to connect to -g, --grepable Produce grepable output -B, --browse Browse SMB servers using DNS Help options: -?, --help Show this help message --usage Display brief usage message Common samba options: -d, --debuglevel=DEBUGLEVEL Set debug level -s, --configfile=CONFIGFILE Use alternate configuration file -l, --log-basename=LOGFILEBASE Base name for log files -V, --version Print version --option=name=value Set smb.conf option from command line Connection options: -O, --socket-options=SOCKETOPTIONS socket options to use -n, --netbiosname=NETBIOSNAME Primary netbios name -W, --workgroup=WORKGROUP Set the workgroup name -i, --scope=SCOPE Use this Netbios scope Authentication options: -U, --user=USERNAME Set the network username -N, --no-pass Don't ask for a password -k, --kerberos Use kerberos (active directory) authentication -A, --authentication-file=FILE Get the credentials from a file -S, --signing=on|off|required Set the client signing state -P, --machine-pass Use stored machine account password -e, --encrypt Encrypt SMB transport -C, --use-ccache Use the winbind ccache for authentication --pw-nt-hash The supplied password is the NT hash </password> |
NOTES
-
Some servers are fussy about the case of supplied usernames, passwords, share names (AKA service names) and machine names. If you fail to connect try giving all parameters in uppercase.
-
It is often necessary to use the -n option when connecting to some types of servers. For example OS/2 LanManager insists on a valid NetBIOS name being used, so you need to supply a valid name that would be known to the server.
-
smbclient supports long file names where the server supports the LANMAN2 protocol or above.
ENVIRONMENT VARIABLES
-
The variable USER may contain the username of the person using the client. This information is used only if the protocol level is high enough to support session-level passwords.
-
The variable PASSWD may contain the password of the person using the client. This information is used only if the protocol level is high enough to support session-level passwords.
-
The variable LIBSMB_PROG may contain the path, executed with system(), which the client should connect to instead of connecting to a server. This functionality is primarily intended as a development aid, and works best when using a LMHOSTS file
Install
- 客户端程序的位置是单个系统管理员的问题。以下是一些建议。
- 建议将smbclient软件安装在 1. /usr/local/samba/bin/ 或 2. /usr/samba/bin/ 目录中,所有这些目录都可读,只有root用户可写。客户端程序
- 客户端程序本身应该是可执行的。客户端不应该是 set uid 或 set gid!
- 要测试客户机,需要知道运行的 SMB/CIFS 服务器的名称。可以将 smbd(8) 作为普通用户运行
- 在用户可访问的端口上运行该服务器作为守护进程。(通常,超过1024的端口号)将提供一个合适的测试服务器。
DIAGNOSTICS
-
Most diagnostics issued by the client are logged in a specified log file. The log file name is specified at compile time, but may be overridden on the command line.
-
The number and nature of diagnostics available depends on the debug level used by the client. If you have problems, set the debug level to 3 and peruse the log files.
VERSION
- This man page is correct for version 3.2 of the Samba suite.
示例
- -L 列出指定的IP, 在bash上访问 SMB 远程服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
smbclient -L 10.12.1.99 -U Administrator # 查看指定的 SMB 服务器共享列表 Enter SAMBA\Administrator s password: # 输入密码 Domain=[LSZYZX] OS=[Windows Server 2008 R2 Enterprise 7601 Service Pack 1] Server=[Windows Server 2008 R2 Enterprise 6.1] Sharename Type Comment --------- ---- ------- ADMIN$ Disk 远程管理 C$ Disk 默认共享 IPC$ IPC 远程 IPC NETLOGON Disk Logon server share Share Disk SYSVOL Disk Logon server share Connection to 10.12.1.99 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND) NetBIOS over TCP disabled -- no workgroup available |
- -U user%password 直用指定用户名和密码,在bash上访问SMB服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
smbclient -L 10.12.1.99 -U Administrator%1qaz@WSX # # 查看指定的 SMB 服务器共享列表 Domain=[LSZYZX] OS=[Windows Server 2008 R2 Enterprise 7601 Service Pack 1] Server=[Windows Server 2008 R2 Enterprise 6.1] Sharename Type Comment --------- ---- ------- ADMIN$ Disk 远程管理 C$ Disk 默认共享 IPC$ IPC 远程 IPC NETLOGON Disk Logon server share Share Disk SYSVOL Disk Logon server share Connection to 10.12.1.99 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND) NetBIOS over TCP disabled -- no workgroup available |
- 登陆指定的 SMB 服务器
1 2 3 4 5 6 7 8 9 10 11 12 13 |
smbclient \\\\10.12.1.99\\Share -U Administrator # 登入指定的 SMB 服务器 Enter SAMBA\Administrator s password: Domain=[LSZYZX] OS=[Windows Server 2008 R2 Enterprise 7601 Service Pack 1] Server=[Windows Server 2008 R2 Enterprise 6.1] smb: \> ls # 列出服务器上的文件 . D 0 Wed May 30 17:39:52 2018 .. D 0 Wed May 30 17:39:52 2018 TableTextService D 0 Wed May 30 17:39:53 2018 13081087 blocks of size 4096. 7418884 blocks available smb: \> |
- put 将指定的文件传送 SMB 服务器上
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
smbclient \\\\10.12.1.99\\Share -U Administrator Enter SAMBA\Administrator s password: Domain=[LSZYZX] OS=[Windows Server 2008 R2 Enterprise 7601 Service Pack 1] Server=[Windows Server 2008 R2 Enterprise 6.1] smb: \> put ./.viminfo \vim\viminfo.txt # 将文件 .viminfi 传说到SMB服务器上的 vim 文件夹里面,并将文件民命为 viminfo.txt putting file ./.viminfo as \vim\viminfo.txt (1136.7 kb/s) (average 1136.7 kb/s) smb: \> cd vim # 进入 vim 文件夹 smb: \vim\> ls # 列出当前文件夹中的文件 . D 0 Wed May 30 18:08:27 2018 .. D 0 Wed May 30 18:08:27 2018 viminfo.txt A 2328 Wed May 30 18:06:29 2018 # 可以看到 viminfo.txt 文件已经传送到服务器上 13081087 blocks of size 4096. 7418879 blocks available |
- get 将SMB服务器上的文件传送回本机
1 2 3 4 5 6 7 8 9 |
smbclient \\\\10.12.1.99\\Share -U Administrator # 登入指定的SMB服务器 Enter SAMBA\Administrator s password: Domain=[LSZYZX] OS=[Windows Server 2008 R2 Enterprise 7601 Service Pack 1] Server=[Windows Server 2008 R2 Enterprise 6.1] smb: \> get vim\viminfo.txt ./vimtect.txt # 将viminfo.txt 文件传送到当前用户的家目录下,文件民命为 vimtect.txt getting file \vim\viminfo.txt of size 2328 as ./vimtect.txt (757.8 KiloBytes/sec) (average 909.4 KiloBytes/sec) |
- 1 -c “mkdir name” 在 SMB 服务器上的创建一个目录
1 2 3 4 5 6 |
smbclient -c "mkdir dir" \\\\10.12.1.99\\Share -U Administrator # 在SMB服务器上创建一个文件夹,名称为 dir Enter SAMBA\Administrator's password: Domain=[LSZYZX] OS=[Windows Server 2008 R2 Enterprise 7601 Service Pack 1] Server=[Windows Server 2008 R2 Enterprise 6.1] |
- 例子 -Tc 将SMB服务器上的指定文件打包成 tar 文件并传送回本机
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
smbclient \\\\10.12.1.99\\Share -U Administrator -Tc table.tar table/* # 登入指定的 SMB 服务器,并将服务器上table目录中的所有文件,打包成 table.tar 文件包,并传送回本机 Enter SAMBA\Administrator s password: Domain=[LSZYZX] OS=[Windows Server 2008 R2 Enterprise 7601 Service Pack 1] Server=[Windows Server 2008 R2 Enterprise 6.1] tar:712 Total bytes received: 42408166 ls -alh # 可以考到文件包 table.tar 已经传送回本机 总用量 41M drwxrwxr-x. 2 net net 23 5月 30 19:04 . drwx------. 3 net net 111 5月 30 18:48 .. -rw-rw-r--. 1 net net 41M 5月 30 19:04 table.tar tar -xvf table.tar # 可以看到从SMB服务器上打包回来的文件成功在本机解压 ./table/en-US/ ./table/March, 2017 Security Only Quality Update for Windows Server 2008 R2 for x64-based Systems (KB4012212)/ ./table/March, 2017 Security Only Quality Update for Windows Server 2008 R2 for x64-based Systems (KB4012212)/AMD64-all-windows6.1-kb4012212-x64_2decefaa02e2058dcd965702509a992d8c4e92b3.msu ./table/TableTextService.dll ./table/TableTextServiceAmharic.txt ./table/TableTextServiceArray.txt ./table/TableTextServiceDaYi.txt ./table/TableTextServiceSimplifiedQuanPin.txt ./table/TableTextServiceSimplifiedShuangPin.txt ./table/TableTextServiceSimplifiedZhengMa.txt ./table/TableTextServiceYi.txt ./table/zh-CN/ ./table/zh-CN/TableTextService.dll.mui |