Command-line gems: smbclient

Aug 16, 10:13 am

Utilizing file shares on Windows workstations can be a mystifying experience. Computers can appear and disappear from the network, without any good reason. This can be avoided by correctly configuring network resources but many smaller networks, of just a handful of workstations, lack such luxuries. This is especially true if they rely on workstation-based shares rather than a centralized server.

There are a number of ways for a Linux client to deal with this kind of environment. Perhaps the best way is to create a SMB (Windows) mount that specifies an IP address, instead of a NetBIOS machine name. But for quick and dirty probing and usage of SMB shares, the smbclient application can be used.

If you've ever used an FTP client then you'll feel right at home because that's what smbclient is styled after. Once connected you can use the familier get and put commands to transfer files, as well as misc shell commands like ls to change directories. The help command displays available commands, as with most FTP clients.

Start by probing the workstation you want to connect to in order to see what's available. For example, I used the following to probe a Windows XP Professional machine with the IP address 192.168.1.3:

smbclient -L //192.168.1.3/

Note the way that the address has to be formed, with two slashes at the front.

The result of the probe should be a list of the shared folders, along with other shared resources, such as printers.

You might also the try the NetBIOS name, instead of an IP address. For example, my office machine's name is KEIR-OFFICE, and I could specify this instead of an IP address. However, as mentioned above, this isn't guaranted to work:

smbclient -L //KEIR-OFFICE/

Then, to connect, specify the address of the machine along with the share folder/service name (in this case, pictures):

smbclient //192.168.1.3/pictures

You'll be prompted for a password even if the computer you're trying to connect to doesn't need one (as with Windows XP Home machines). If that's the case then simply leave the password blank and hit Enter. If you need to specify a username for the shared resource then you can do so with the -U command option:

smbclient -U keir //192.168.1.3/pictures


    1. imdb says:

      You forgot to write about smbtree, the tool you use to find accessable shares. you also forgot to mention smbmount.

      Tomorrow you can write about how you can use konqueror or nautilus to browse windows shares.

      Then you can can write extensively about ls and rm. Don’t rest yet, there is still much work to do.



    1. The other thing to mention is that SMB is being phased out in favour of CIFS on Fedora/RHEL.




Add your comments

Please keep your comments relevant to this blog entry: inappropriate or purely promotional comments may be removed. To add hyperlink, please follow this example: "your link text":http://your.link.url