Linux smbclient Command Tutorial

SMB is a popular protocol used to share files over the network. Even it is created for Windows operating systems it is supported by Linux distributions too. The smbclient command can be used to access Windows shares easily. By using smbclient the remote Windows shares can be listed, uploaded, deleted, or navigated easily. The smbclient command also provides an interactive shell.

Install smbclient

The smbclient command is provided with the smbclient package name for the most of the Linux distributions. This package also described as “command-line SMB/CIFS clients for Unix”.

Debian, Ubuntu, Mint, Kali:

sudo apt install smbclient

CentOS, RHEL, Fedora:

sudo dnf install smbclient

List SMB Shares

The smbclient can be used for different actions but the most popular usage is listing the shares for the specified SMB/CIFS Windows share service for the remote system. The -L option is used with the smbclient command to list all shares.

smbclient -L fileserver

Alternatively, the remote server IP address can be used in order to list shares with the -L option. In the following example, we list the shares provided by the IP address 192.168.1.10.

smbclient -L 192.168.1.10

List SMB Shares Providing Username

The windows share may require access with credentials by providing a username and password. So in order to list SMB shares we should provide the username and password. The -U option is used to specify the username. In the following example, we specify the username as “ismail” to list shares on the remote fileserver.

smbclient -L fileserver -U ismail

After specifying the username the password for this user is requested.

List Specified Share Path Content

The smbclient can be used to list specified path or directory contents. It is very same to list shares where the path is added after the remote share hostname or IP address. In the following example we list contents of the “\Backup\2021”.

smbclient -L \\fileserver\Backup\2021

Alternatively the IP address of the file sharing host can be used like below.

smbclient -L \\192.168.1.10\Backup\2021

Smb Client Interactive Shell

One of the most powerfull features of the smbclient is its interactive shell. The remote share can be connected like and FTP and a new shell is provided via the smbclient. This shell can be used to navigate, list, upload, download, etc. file. The the smb shell can be started just providing the remote share.

smbclient "\\fileserver\Backup"

If required the username can be provided with the -U option and then the password is prompted automatically.

smbclient "\\fileserver\Backup" -U ismail

List Files and Folders

In the smbclient interactive shell we can list files with the ls command.

smb: \> ls

Upload Files and Folders

Files and folders can be uploaded with the mput command. But in order to upload specified folder and its content the recursive mode should be enabled with the recurse command. Also the upload can be started with the mput command.

smb: \> recurse
smb: \> mput pictures
smb: \> mput /home/ismail/downloads

Download Files and Folders

Files and folders can be also downloaded with the mget command. If there are multiple files and folders to download the recursive mode should be enabled with the recurse command.

smb: \> recurse
smb: \> mget pictures

List Files and Folders Attributes

Like a local file and folder the SMB shared files and folders have different attributes. These attributes can be size, permissions, NTFS attributes etc. The files and folders attributes can be listed with the allinfo command by specifiying the file name.

smb: \> allinfo data.txt

Error NT_STATUS_CONNECTION_REFUSED

The smbclient try to connect remote windows share service which runs over SMB ports. If these ports are not accessable because of different reasons we may get an error like “Error NT_STATUS_CONNECTION_REFUSED“. The “Error NT_STATUS_CONNECTION_REFUSED” error is related with network and firewall. The service may not not running or firewall blocks access to this services or there is a network problem.

Leave a Comment