smbclient Security for Windows Printing and File T...
Microsoft Windows is usually a presence in most computing environments, and UNIX administrators likely will be forced to use resources in Windows networks from time to time. Although many are familiar with the Samba server software, the matching smbclient utility often escapes notice.
The 'map network drive' function of Windows relies upon the Server Message Blocknetwork protocol that has evolved chiefly within the descendents of NT. The smbclient utility presents an interface reminiscent of FTP that allows file transfer to and from disk directories and printers on an NT server over SMB where sharing is enabled.
In this article, I present connection examples for Windows services, then develop a general script for pushing content to Windows shares. I discuss when the SMB protocols should be used and, more important, when they should not.
Connection Examples
Samba for UNIX is well known for server software that interoperates with clients on Windows networks. However, it also includes the smbclient program that can manipulate any SMB server. The smbclient program will be immediately familiar to those experienced with command-line FTP.
The smbclient program can query SMB servers for a list of visible shares using the -L
option:
$ smbclient -L dc.somecompany.com -U nt_username -W nt_domainEnter nt_username's password:Domain=[NT_DOMAIN]OS=[Windows Server 2008 R2 Standard 7601 Service Pack 1]Server=[Windows Server 2008 R2 Standard 6.1] Sharename Type Comment --------- ---- ------- C$ Disk Default share file_stash Disk Fancy_laser Printer Really Expensive Cheap_laser Printer What a deal!
After cataloging the file and printer shares on a server, you can connect to a specific share and manipulate it. Below are examples of several types of transfers:
$ smbclient //dc.somecompany.com/file_stash -U nt_username -W nt_domainEnter nt_username's password:Domain=[NT_DOMAIN]OS=[Windows Server 2008 R2 Standard 7601 Service Pack 1]Server=[Windows Server 2008 R2 Standard 6.1]smb: \> mkdir 'smbclient test'smb: \> cd 'smbclient testsmb: \smbclient test\> promptsmb: \smbclient test\> mput samba*putting file samba.schema.oc.IBM-DS as \smbclient test\samba.schema.oc.IBM-DS (955.7 kb/s) (average 955.7 kb/s)putting file samba.schema.at.IBM-DS as \smbclient test\samba.schema.at.IBM-DS (3590.1 kb/s) (average 2272.9 kb/s)putting file samba.schema as \smbclient test\samba.schema (7454.2 kb/s) (average 4000.1 kb/s)putting file samba.ldif as \smbclient test\samba.ldif (1615.9 kb/s) (average 2808.0 kb/s)putting file samba-schema.IBMSecureWay as \smbclient test\samba-schema.IBMSecureWay (1023.7 kb/s) (average 2553.1 kb/s)putting file samba-schema-netscapeds5.x.README as \smbclient test\samba-schema-netscapeds5.x.README (61.0 kb/s) (average 2336.4 kb/s)putting file samba-schema-FDS.ldif as \smbclient test\samba-schema-FDS.ldif (5572.1 kb/s) (average 2709.8 kb/s)putting file samba-nds.schema as \smbclient test\samba-nds.schema (247.3 kb/s) (average 862.9 kb/s)smb: \smbclient test\> dir . D 0 Fri Mar 3 13:31:24 2017 .. D 0 Fri Mar 3 13:31:24 2017 samba-nds.schema A 19754 Fri Mar 3 13:31:24 2017 samba-schema-FDS.ldif A 17118 Fri Mar 3 13:31:24 2017 samba-schema-netscapeds5.x.README A 125 Fri Mar 3 13:31:24 2017 samba-schema.IBMSecureWay A 3145 Fri Mar 3 13:31:24 2017 samba.ldif A 14892 Fri Mar 3 13:31:24 2017 samba.schema A 22900 Fri Mar 3 13:31:24 2017 samba.schema.at.IBM-DS A 11029 Fri Mar 3 13:31:24 2017 samba.schema.oc.IBM-DS A 2936 Fri Mar 3 13:31:24 2017
708626943 blocks of size 4096.
95072482 blocks availablesmb: \smbclient test\> lcd /tmpsmb: \smbclient test\> get samba.schema.oc.IBM-DSgetting file \smbclient test\samba.schema.oc.IBM-DS of size 2936 as samba.schema.oc.IBM-DS (409.6 KiloBytes/sec) (average 409.6 KiloBytes/sec)smb: \> help? allinfo altname archive backupblocksize cancel case_sensitive cd chmodchown close del dir duecho exit get getfacl geteashardlink help history iosize lcdlink lock lowercase ls lmask md mget mkdir moremput newer notify open posixposix_encrypt posix_open posix_mkdir posix_rmdir posix_unlinkprint prompt put pwd qqueue quit readlink rd recursereget rename reput rm rmdirshowacls setea setmode scopy statsymlink tar tarmode timeout translateunlock volume vuid wdel logonlistconnect showconnect tcon tdis tidlogoff .. !smb: \> quit
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。