smbclient
Access SMB/CIFS shares from the command line
TLDR
Connect to a share (user will be prompted for password; exit to quit the session)
Connect with a different username
Connect with a different workgroup
Connect with a username and password
Download a file from the server
Upload a file to the server
List the shares from a server anonymously
SYNOPSIS
smbclient //server/share [password] [options]
smbclient -L //server [options]
smbclient -M netbios_name [options]
PARAMETERS
//server/share
Specifies the target SMB/CIFS share. This is the primary argument for accessing a specific share.
-L //server
Lists the shares available on a specified SMB/CIFS server.
-U username[%password]
Specifies the username and optionally the password for authentication. If the password is not provided here, it will be prompted interactively.
-W workgroup
Specifies the workgroup or domain for authentication.
-N
Suppresses the password prompt, useful for shares that do not require authentication.
-A authfile
Reads authentication credentials (username, password, domain) from a specified file, improving security over typing passwords on the command line.
-c 'command_string'
Executes a specified command string directly in non-interactive mode. Useful for scripting single operations like `get file.txt` or `ls`.
-I ip_address
Specifies the IP address of the server to connect to, bypassing name resolution.
-p port
Specifies the TCP port number to connect to (default is 445 or 139).
-T
Enables tar backup mode. `c` for create (backup), `x` for extract (restore) to/from a tar file. Used for backing up or restoring entire directories.
-D directory
Changes the current working directory on the remote share immediately after connection.
-M netbios_name
Sends a message to another NetBIOS client or server.
DESCRIPTION
smbclient is a powerful command-line utility within the Samba suite that allows Unix/Linux systems to interact with SMB/CIFS network shares. These shares are commonly found on Windows servers, other Samba servers, or network-attached storage (NAS) devices. It acts as an FTP-like client, enabling users to list share contents, download files, upload files, create directories, and perform other file management operations remotely. smbclient supports both interactive and non-interactive modes, making it suitable for scripting automated tasks as well as direct user interaction. It's an essential tool for cross-platform file sharing and system administration in mixed environments.
CAVEATS
smbclient requires proper network connectivity and correct credentials to access remote shares. Entering passwords directly on the command line using -U username%password can be a security risk as it exposes credentials in process lists and shell history; using the -A option with an authentication file is generally preferred for security. The behavior can also be influenced by the server's SMB protocol version and encryption settings. Users must have appropriate permissions on the remote share to perform operations like file uploads or deletions.
INTERACTIVE VS. NON-INTERACTIVE MODE
When connecting to a share without the -c option, smbclient enters an interactive prompt similar to an FTP client, allowing users to type commands like ls, get, put, cd, and exit. Using the -c option enables non-interactive mode, where a single command string is executed, making it ideal for scripting automated tasks without user intervention.
TAR BACKUP MODE
The -T option transforms smbclient into a powerful backup and restore tool for network shares. It allows creating a tar archive of a remote directory (-T c tarfile) or extracting files from a local tar archive onto a remote share (-T x tarfile), providing an efficient way to manage large sets of files for backup purposes.
HISTORY
smbclient is an integral part of the Samba project, which began in 1992. Samba was developed to enable Unix and Linux systems to seamlessly interoperate with Microsoft Windows networks, specifically to provide file and print services compatible with the Server Message Block (SMB) protocol, later renamed Common Internet File System (CIFS). smbclient emerged as the command-line utility for Unix-like systems to act as clients in these SMB/CIFS environments, offering a robust way to access and manage network resources shared by Windows machines or other Samba servers. Its development has mirrored the evolution of the SMB/CIFS protocol itself, adapting to new features and security enhancements over decades.