smbclient
smbclient
is a command-line tool in Samba that allows users to interact with Windows network shares and printers. It provides an FTP-like interface to access and manage files on SMB/CIFS servers, including Windows machines and other Samba servers. This tool is useful for transferring files, accessing shared directories, and testing SMB connections.
General Usage
Common Options
-L host
: List shares available on a host.-U user
: Specify the username for authentication.-W workgroup
: Specify the workgroup or domain.-I ip_address
: Specify the IP address of the host.-c command
: Execute a command immediately after connecting.
Basic Usage Examples
List Shares on a Server
This command lists all available shares on the specified server.
Example:
Output:
Connecting to a Share
This command connects to a specific share on the server.
Example:
Output:
Uploading a File
Once connected to a share, you can upload files using the
put
command.Example:
Output:
Downloading a File
Similarly, you can download files using the
get
command.Example:
Output:
Listing Files in a Directory
Example:
Output:
Creating a Directory
Example:
Output:
Deleting a File
Example:
Output:
Executing Multiple Commands
You can execute multiple commands by using the
-c
option.Example:
Output:
Advanced Usage
Authenticating with a Password File
Instead of entering a password interactively, you can use a credentials file.
Create a Credentials File
Use the Credentials File
Example:
Using Kerberos Authentication
If your network uses Kerberos for authentication, you can connect using your Kerberos ticket.
Obtain a Kerberos Ticket
Connect with Kerberos Authentication
Example:
Summary
smbclient -L //hostname -U username
List available shares on a server
smbclient -L //server -U myuser
smbclient //hostname/sharename -U username
Connect to a specific share
smbclient //server/public -U myuser
smb: \> put localfile remotefile
Upload a file to the connected share
put /path/to/localfile.txt remotefile.txt
smb: \> get remotefile localfile
Download a file from the connected share
get remotefile.txt /path/to/localfile.txt
smb: \> ls
List files in the current directory
ls
smb: \> mkdir dirname
Create a new directory
mkdir newfolder
smb: \> del filename
Delete a file
del oldfile.txt
smbclient //hostname/sharename -A /path/to/credentialsfile
Use a credentials file for authentication
smbclient //server/public -A /path/to/credentials.txt
smbclient //hostname/sharename -k
Use Kerberos authentication
smbclient //server/public -k
Conclusion
smbclient
is a powerful tool for interacting with SMB/CIFS shares from the command line. It provides a wide range of options and commands for accessing, managing, and transferring files on network shares. Whether you need to list available shares, connect to a specific share, or perform file operations, smbclient
offers the functionality needed for effective network file management in a Samba environment. Understanding its options and commands is essential for system administrators and users working with network shares.
Last updated