LinuxCommandLibrary

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)

$ smbclient [//server/share]
copy

Connect with a different username
$ smbclient [//server/share] --user [username]
copy

Connect with a different workgroup
$ smbclient [//server/share] --workgroup [domain] --user [username]
copy

Connect with a username and password
$ smbclient [//server/share] --user [username%password]
copy

Download a file from the server
$ smbclient [//server/share] --directory [path/to/directory] --command "get [file.txt]"
copy

Upload a file to the server
$ smbclient [//server/share] --directory [path/to/directory] --command "put [file.txt]"
copy

List the shares from a server anonymously
$ smbclient --list=[server] --no-pass
copy

SYNOPSIS

smbclient {service} [password] [options]

PARAMETERS

service
    Specifies the SMB/CIFS service to connect to, in the format //server/share. If only one slash is used, smbclient will list available share names.

password
    Provides the password for accessing the service. If not provided, smbclient will prompt for it.

-U username[%password]
    Specifies the username to use when connecting. You can also include the password after a % sign. If the username is not provided, the current user will be used.

-L hostname
    Lists the available shares on the specified server (equivalent to '//hostname' service).

-N
    Suppresses password prompting. Useful for anonymous connections.

-g
    Dumps the core file upon exit.

-p portnumber
    Specifies the port number to use for the connection.

-d debuglevel
    Sets the debug level. Higher values produce more verbose output.

-m protocol
    Specifies the SMB protocol version to use (e.g., SMB2, SMB3).

-c command
    Executes a single command and then exits.

-W workgroup
    Sets the NetBIOS workgroup name.

DESCRIPTION

smbclient is a command-line client for accessing SMB/CIFS shares on a network.
It allows users to interact with shared directories and printers hosted on Windows or Samba servers.
Using smbclient, you can list available shares, download and upload files, and perform other file management tasks.
It provides a text-based interface, resembling an FTP client, for navigating and manipulating files on remote SMB/CIFS servers. The command is very useful for command-line automation scripts.

CAVEATS

smbclient relies on the Samba suite being properly configured to function correctly. Permissions and server settings can affect the ability to connect to and interact with shares. Problems with name resolution can occur if proper DNS setup is not in place.

INTERACTIVE COMMANDS

When smbclient is run without the -c flag, it enters an interactive shell. Within this shell, you can use commands like 'ls', 'cd', 'get', 'put', 'mget', 'mput', 'del', 'mkdir', 'rmdir', 'print', and 'queue' to manage files and printers.

AUTHENTICATION

smbclient supports various authentication methods, including username/password, Kerberos, and NTLM. The -U option lets you specify a username, and the -k option enables Kerberos authentication. When connecting anonymously, use the -N option to suppress password prompting.

HISTORY

smbclient has evolved as part of the Samba project, which was initially developed by Andrew Tridgell in the early 1990s. The goal was to enable seamless file and printer sharing between Unix-like systems and Windows machines using the SMB protocol.
Over time, smbclient has been enhanced to support newer SMB versions and various authentication methods, improving compatibility with modern Windows systems.
Its command-line interface has remained relatively consistent, making it a reliable tool for system administrators and developers.

SEE ALSO

smbd(8), nmbd(8), mount.cifs(8)

Copied to clipboard