Make Samba Work Right (for Linux & MacOS)

· cyclicircuit's blog

How to configure SAMBA so that it works right with Linux and MacOS

One of the persistent frustrations in my life is that Samba/SMB has weird issues around character encoding. This has gotten so bad in the past that I simply gave up on it. It works great for Windows, but with Linux and MacOS clients I ended up running into serious issues, particularly because English is not the only language which I use in filenames. Over time, I figured out that there is a series of magical configuration options, buried deep in the Samba documentation that make it work for Linux and MacOS and I don't think it breaks Windows (though I am not sure about that last part).

Why this isn't the default, I have no idea.

Anyway, this is how we unfuck Samba for Linux/MacOS - in the /etc/samba/smb.conf we need to set global character encodings:

24   │ [global]
25   │    mangled names = yes # it doesn't really matter what you set this one as, since we're going to set it explicitly for each share
26   │    dos charset = CP850
27   │    unix charset = UTF-8

and then for every share, we need to configure like so:

This is the ansible jinja2 template I use:

 1[{{ item.name }}]
 2    comment = {{ item.comment }}
 3    path = {{ item.path }}
 4    browseable = {{ 'yes' if item.browseable else 'no' }}
 5    writable = {{ 'yes' if item.writable else 'no' }}
 6    guest ok = no
 7    valid users = {{ item.valid_users }}
 8    create mask = 0744
 9    directory mask = 0755
10    mangled names = no
11    vfs objects = catia fruit
12    fruit:encoding = native
13    catia:mappings = 0x22:0xa8,0x2a:0xa4,0x2f:0xf8,0x3a:0xf7,0x3c:0xab,0x3e:0xbb,0x3f:0xbf,0x5c:0xff,0x7c:0xa6

And this is what the final result looks like:

247   │ [storage]
248   │     comment = Infosphere storage array
249   │     path = /storage
250   │     browseable = yes
251   │     writable = yes
252   │     guest ok = no
253   │     valid users = cyclicircuit
254   │     create mask = 0744
255   │     directory mask = 0755
256   │     mangled names = no
257   │     vfs objects = catia fruit
258   │     fruit:encoding = native
259   │     catia:mappings = 0x22:0xa8,0x2a:0xa4,0x2f:0xf8,0x3a:0xf7,0x3c:0xab,0x3e:0xbb,0x3f:0xbf,0x5c:0xff,0x7c:0xa6

Sincerest apologies to all the forum posts where I gathered this information over the years, I simply don't have the links to you anymore. If I did, I would cite them.

last updated: