smbclient Cheat Sheet
Below is a cheat sheet for smbclient
, a command-line tool used to access and manipulate files on servers running the Server Message Block (SMB) protocol, commonly used in Windows networks:
Basic Usage:
- Connect to a Share:
smbclient //<server>/<share> -U <username>
- Authenticate with Password:
smbclient //<server>/<share> -U <username>%<password>
- Anonymous Connection:
smbclient //<server>/<share>
Commands:
ls
– List Files:
smb: \> ls
cd
– Change Directory:
smb: \> cd <directory>
get
– Download File:
smb: \> get <filename>
put
– Upload File:
smb: \> put <local_file>
mget
– Download Multiple Files:
smb: \> mget <pattern>
mput
– Upload Multiple Files:
smb: \> mput <pattern>
mkdir
– Create Directory:
smb: \> mkdir <directory>
rmdir
– Remove Directory:
smb: \> rmdir <directory>
rm
– Remove File:
smb: \> rm <filename>
rename
– Rename File:smb: \> rename <old_name> <new_name>
prompt
– Toggle Interactive Mode:smb: \> prompt
quit
orexit
– Quitsmbclient
:smb: \> quit
Options:
-U
– Specify Username:
smbclient //<server>/<share> -U <username>
-N
– Use Null Session:
smbclient //<server>/<share> -N
-W
– Specify Workgroup:
smbclient //<server>/<share> -W <workgroup>
-c
– Execute Commands:
smbclient //<server>/<share> -U <username> -c 'ls; get <filename>'
Examples:
- Connect and List Files:
smbclient //server/share -U username
smb: \> ls
- Download File:
smbclient //server/share -U username
smb: \> get file.txt
- Upload File:
smbclient //server/share -U username
smb: \> put local_file.txt
- Interactive Mode:
smbclient //server/share -U username
smb: \> prompt
- Connect with Null Session:
smbclient //server/share -N
Note:
- Ensure you have necessary permissions to access the SMB share.
- Replace placeholders like
<server>
,<share>
,<username>
, and<password>
with actual values. - Use
-N
for null sessions only if allowed and required.
Resources:
- Samba Documentation
- Online tutorials and forums for additional guidance and tips.
This cheat sheet provides an overview of common smbclient
commands and options for accessing and interacting with SMB shares. Adjustments may be necessary based on specific requirements and configurations. Always ensure compliance with security policies and legal regulations when accessing remote systems.