Special characters in Samba filenames
When serving files containing special characters such as "()?:" in the filename through Samba, the names get transformed into an unrecognizable format. For example, a file
my_file:_(important).txt
is displayed as
M43J1E~0.TXT
Is there a way to avoid this behavior (without renaming the files, obviously)? I'm assuming that character encoding is not to blame because several UTF-8 characters seem to work fine.
Solution 1:
I own an Apple Macbook Pro laptop with 64-bit OS X 10.11 "El Capitan" running Samba 3 that I installed through Macports.
I also own a Dell Inspiron laptop with 64-bit GNU/Linux XUbuntu 16.04 "Xenial Xerus" running Samba 3 that I installed through APT.
Both machines have network-shared folders and use Samba in order to communicate on my WLAN (wireless LAN).
Both my systems are in Brazilian Portuguese. Thus, I use special characters such as ç, á, ã, â, ô, é, ó et cetera.
When I use my Linux laptop to access my OS X Samba shares, all strings are shown correctly: words like maçã, ônus and bênção are shown correctly. Files and folders with long names are also shown, and their names are shown correctly. Thus, the Samba server running on OS X is already properly configured...
...but things weren't working the other way around: if I used the Finder app on OS X to access my Linux Samba shares, all files and folders having at least one of those special characters were not shown (they remained invisible to me), and the long names of files and folders were converted to weird short names. Thus, there was something wrong with the Samba server running on my Linux machine.
=> In my case, what solved this issue was adding the following lines to the [global]
section inside the smb.conf
file on my Linux machine:
mangled names = no
dos charset = CP850
unix charset = UTF-8
After that, I opened a shell terminal window and restarted the Linux Samba server with this command:
sudo service smbd restart
...which can be replaced by this other command (in case the command above doesn't work on your Linux distribution):
sudo systemctl restart smbd.service
After I restarted the Linux Samba server, the Finder app on OS X finally showed correctly all the files and folders that were previously hidden because of their names having one or more special characters. The mangled ("shortened") names were also "unmangled".
Footnotes:
- In GNU/Linux systems, the standard location of the
smb.conf
file is/etc/samba/smb.conf
- Presuming that your Linux system has the
smb.conf
file stored at the standard location/etc/samba/
: there are several different ways to edit thesmb.conf
file. For instance, if you're not using a Desktop Environment (e.g. your system has only a shell terminal, no windows) you can install the Nano text editor, by issuing a command such assudo apt-get install nano -y
orsudo dnf -b -y install nano
or something else (depending on which Linux distro you are using), and then runsudo nano /etc/samba/smb.conf
. In case you're using a Desktop Environment, you can install a graphical text editor such as GNOME Edit, by issuing a command such assudo apt-get install gedit -y
orsudo dnf -b -y install gedit
or something else (depending on which Linux distro you are using), and then runsudo gedit /etc/samba/smb.conf
. - In Samba 3+, the
display charset
parameter is deprecated. - The
dos charset
parameter does not support theUTF-8
argument. Thus, it must use the default argumentCP850
. -
mangled names = no
instructs the Samba server not to shorten long names of files and folders. Hence, because the Samba client just replicates to the user what the Samba server has provided to the client, once the server is properly configured the client will no longer show the user any shortened name.
Solution 2:
Windows does not allow some characters in filenames that Unix does allow. Samba "mangles" the filenames to make them comply with Windows restrictions. You can check the file /etc/smb.conf
or /etc/samba/smb.conf
to see what settings are in place. To show those settings plus the defaults, use this command:
testparm -vs | less
To narrow that down a bit:
testparm -vs|grep "case\|mangl"
See this page for more information. Also, see about half way down this page (the same information as the previous link).
Solution 3:
I use a shared folder on OS-X and Windows. Some files have the same issue, because they fall into the following: They use characters in the file-name, not supported by Windows.
See: http://support.microsoft.com/kb/177506
It lists the characters, not supported by Windows in files or directories. I guess, that Samba uses the same list of characters when listing files and directories.
A filename cannot contain any of the following characters:
\ / : * ? " < > |
A bit further down, they wrote:
Characters that are valid for naming files, folders, or shortcuts include any combination of letters (A-Z) and numbers (0-9), plus the following special characters:
^ Accent circumflex (caret) & Ampersand ' Apostrophe (single quotation mark) @ At sign { Brace left } Brace right [ Bracket opening ] Bracket closing , Comma $ Dollar sign = Equal sign ! Exclamation point - Hyphen # Number sign ( Parenthesis opening ) Parenthesis closing % Percent . Period + Plus ~ Tilde _ Underscore
But I, personally, took the listing of not-allowed characters as a reference for briefing some customers here ;)
Solution 4:
from samba documentation you can use these:
dos charset = ISO8859-1
unix charset = ISO8859-1
display charset = ISO8859-1