Gleaning from the Arch Linux Wiki entry, I have what I think is the minimal setup of accessing a Windows shared drive via SMB from my Arch Linux 4.20.6:

  • sudo pacman -Sy samba
  • sudo echo "logging = systemd" >> /etc/samba/smb.conf since the smb service needs this config file, otherwise it'll crash with the error:

    Job for smb.service failed because the control process exited with error code.
    See "systemctl status smb.service" and "journalctl -xe" for details.
  • sudo systemctl start smb

Assuming that the remote Windows machine is at, I'm able to list the share names with

smbclient -L -U MyUserName%MyPassword -W OurWindowsDomain

Among those is a service of type "Disk" with share name OurRemoteDirectory that I'd like to access, i.e., transfer files from and to it.

Hoping to be able to access OurRemoteDirectory on the shared drive, I issued

smbclient -U MyUserName%MyPassword -W OurWindowsDomain

But that produced this error message:

Unable to initialize messaging context Not enough '\' characters in service

How can I fix this error and access OurRemoteDirectory on the shared drive?


To fix this, simply add two forward slashes before the IP address:

smbclient // -U MyUserName%MyPassword -W OurWindowsDomain

What threw me off was the error message suggesting I should add backward slashes and the fact that listing share names with smbclient -L does not require any slashes in front of the IP address.

Now I have a command line interface for accessing the remote file system:

smb: >

Having established the connection, man smbclient describes commands for transferring files, such as put and get.

As a postscript, since v7.40 curl supports the protocol as well, which makes the samba package including smbclient superfluous in cases where you only want to transfer files from and to the shared drive:

# Upload local file to shared drive
curl --upload-file /home/me/local_file.txt --user "OurWindowsDomain/MyUserName:MyPassword" smb://
# Download file from shared drive
curl -o file_from_server.txt --user "OurWindowsDomain/MyUserName:MyPassword" smb://

Currently, curl does not support creating remote directories, meaning Path/To/Dir/ has to exist already. The feature is briefly discussed here.

  • 2
    smbclient understands backslashes too, but because Unix-style shells will parse them as escape characters, you need to inconveniently double them: smbclient \\\\\\OurRemoteDirectory -U MyUserName... – telcoM Feb 4 at 12:58
  • @telcoM, or use single-quotes (in shells other than fish): smbclient '\\\OurRemoteDirectory' (BTW, the rc shell doesn't treat backslash as a quoting character). – Stéphane Chazelas Feb 6 at 10:44
  • Single-quotes don't allow variable expansion inside them, so they can be inconvenient if you need to use smbclient in a script to a target specified by a variable. Other than that, they are indeed a valid alternative. – telcoM Feb 6 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.