From ArchWiki
Jump to navigation Jump to search





Install the samba package.

Samba is configured in the /etc/samba/smb.conf configuration file, which is extensively documented in smb.conf(5).

Because the samba package does not provide this file, one needs to create it before starting smb.service.

A documented example as in smb.conf.default from the Samba git repository may be used to setup /etc/samba/smb.conf.

  • The default configuration sets log file to a non-writable location, which will cause errors - apply one of the following workarounds:
    • Change the log file location to a writable path: log file = /var/log/samba/%m.log
    • Change logging to a non-file backend solution: logging = syslog with syslog only = yes, or use logging = systemd
  • If required; the workgroup specified in the [global] section has to match the Windows workgroup (default WORKGROUP).
Tip: Whenever you modify the smb.conf file, run the testparm(1) command to check for syntactic errors.

Configure Firewall

If you are using a firewall, do not forget to open required ports (usually 137-139 + 445). For a complete list, see Samba port usage.


User Management

Adding a user


Note: The user/user group nobody should already exist on the system, it's used as the default guest account and may be used for shares containing guest ok = yes, thus preventing the need of user login on that share.


# smbpasswd -a samba_user




Also see Security for hardening your system.

Listing users


# pdbedit -L -v
Changing user password

To change a user password, use smbpasswd:

# smbpasswd samba_user

Creating a share

Note: To allow the usage of guests on public shares, one may need to append map to guest = Bad User in the [global] section of /etc/samba/smb.conf. A different guest account may be used instead of the default provided nobody.

Make sure shares have been properly defined as per the Share Definitions section of smb.conf.default.

Starting services



Advanced Configuration

Enable Usershares



# # create directory:
# mkdir /var/lib/samba/usershares
# # create group:
# groupadd -r sambashare
# # change the owner of the directory to 'root' and the group to 'sambashare':
# chown root:sambashare /var/lib/samba/usershares
# # change the permissions of the 'usershares' directory so that users in the group 'sambashare' can read, write and execute files:
# chmod 1770 /var/lib/samba/usershares

Set the following parameters in the smb.conf configuration file:

  usershare path = /var/lib/samba/usershares
  usershare max shares = 100
  usershare allow guests = yes
  usershare owner only = yes

Add the user to the sambashare group. Replace your_username with the name of your user:

# gpasswd sambashare -a your_username

Restart smb.service and nmb.service services.

Log out and log back in.

If you want to share paths inside your home directory you must make it accessible for the group others.

In the GUI, for example in Thunar, you can right click on any directory and share it on the network.

In the CLI, use one of the following commands, replacing italic sharename, user, ... :

# net usershare add sharename abspath [comment] [user:{R|D|F}] [guest_ok={y|n}]
# net usershare delete sharename
# net usershare list wildcard-sharename
# net usershare info wildcard-sharename

Set and forcing permissions

Permissions may be applied to both the server and shares:

  create mask = 0664
  directory mask = 2755
  force create mode = 0644
  force directory mode = 2755

  comment = Media share accessible by greg and pcusers
  path = /path/to/media
  valid users = greg @pcusers
  force group = +pcusers
  public = no
  writable = yes
  create mask = 0664
  directory mask = 2775
  force create mode = 0664
  force directory mode = 2775

  comment = Public share where archie has write access
  path = /path/to/public
  public = yes
  read only = yes
  write list = archie
  printable = no

  comment = Allow all users to read/write
  path = /path/to/guests
  public = yes
  only guest = yes
  writable = yes
  printable = no

See smb.conf(5) for a full overview of possible permission flags and settings.

Restrict protocols for better security

By default Samba allows the usage of (possible) insecure and out-of-dated protocols for compatible reasons.

Append server min protocol and server max protocol in /etc/samba/smb.conf to force usage of a minimum and maximum protocol:

  server min protocol = NT1
  ; server max protocol = SMB3
Note: See server max protocol in smb.conf(5) for an overview of supported protocols.
Tip: Use server min protocol = SMB3 when clients should only connect using the latest SMB3 protocol, e.g. on clients running Windows 8 and later.

Clients using mount.cifs may need to specify the correct vers=*, e.g.:

# mount -t cifs //SERVER/sharename /mnt/mountpoint -o username=username,password=password,iocharset=utf8,vers=3.1.1

See mount.cifs(8) for more information.

Use native SMB transport encryption

Native SMB transport encryption is available in SMB version 3.0 or newer. Clients supporting this type of encryption include Windows 8 and newer, Windows server 2012 and newer, and smbclient of Samba 4.1 and newer.

To use native SMB transport encryption by default, set the smb encrypt parameter globally and/or by share. Possible values are off, enabled (default value), desired, or required:

  smb encrypt = desired

See smb.conf(5) for more information, especially the paragraphs Effects for SMB1 and Effects for SMB2.

Tip: When mounting a share, specify the seal mount option to force usage of encryption.

Disable printer sharing

By default Samba shares printers configured using CUPS.

If you do not want printers to be shared, use the following settings:

  load printers = no
  printing = bsd
  printcap name = /dev/null
  disable spoolss = yes
  show add printer wizard = no

Block certain file extensions on Samba share



  comment = Private
  path = /mnt/data
  read only = no

Improve throughput

Warning: Beware this may lead to corruption/connection issues and potentially cripple your TCP/IP stack.

The default settings should be sufficient for most users. However setting the 'socket options' correct can improve performance, but getting them wrong can degrade it by just as much. Test the effect before making any large changes.


The following settings should be append to the [global] section of /etc/samba/smb.conf.

SMB3 multi-channel may improve performance, however it may result in data corruption under some race conditions. Future releases may improve this situation:

server multi channel support = yes

Setting a deadtime is useful to stop a server's resources being exhausted by a large number of inactive connections:

deadtime = 30

The usage of sendfile may make more efficient use of the system CPU's and cause Samba to be faster:

use sendfile = yes


write cache size = 262144

Setting min receivefile size allows zero-copy writes directly from network socket buffers into the filesystem buffer cache (if available). It may improve performance but user testing is recommended:

min receivefile size = 16384

Reading/writing files asynchronously may improve performance instead of using synchronously writes:

aio read size = 1
aio write size = 1

Increasing the receive/send buffers size and socket optimize flags might be useful to improve throughput. It is recommended to test each flag separately as it may cause issues on some networks:




For a lightweight alternative (without support for listing public shares, etc.), install cifs-utils that provides /usr/bin/mount.cifs.



List public shares

The following command lists public shares on a server:

$ smbclient -L hostname -U%


$ smbtree -b -N


NetBIOS/WINS host names


If you are using apparmor and are unable to start winbind, you may need to add the below two lines to the apparmor profile for winbind:

  /var/cache/samba/msg.lock/* rwk, 
  /run/ rwk,


If it is not already there, add it to look roughly like this:

 hosts: files mymachines myhostname mdns_minimal [NOTFOUND=return] resolve [!UNAVAIL=return] dns wins

You can test WINS resolution with nmblookup. Note that WINS resolution requires incoming traffic originating from port 137.

Disable NetBIOS/WINS support


  disable netbios = yes
  dns proxy = no

Finally disable/stop winbind.service.

Manual mounting

Create a mount point for the share:

# mkdir /mnt/mountpoint


# mount -t cifs //SERVER/sharename /mnt/mountpoint -o username=username,password=password,workgroup=workgroup,iocharset=utf8,uid=username,gid=group

The options uid and gid corresponds to the local (e.g. client) user/user group to have read/write access on the given path.

  • If the uid and gid being used does not match the user of the server, the forceuid and forcegid options may be helpful. However note permissions assigned to a file when forceuid or forcegid are in effect may not reflect the the real (server) permissions. See the File And Directory Ownership And Permissions section in mount.cifs(8) for more information.
  • To allow users to mount it as long as the mount point resides in a directory controllable by the user; i.e. the user's home, append the users mount option. The option is users (plural). For other filesystem types handled by mount, this option is usually user; sans the "s".
  • To mount a Windows share without authentification, use "username=*".
Warning: Using uid and/or gid as mount options may cause I/O errors, it is recommended to set/check correct File permissions and attributes instead.


The server name.


The shared directory.


The local directory where the share will be mounted.

-o [options]

See mount.cifs(8) for more information.

Storing share passwords

Storing passwords in a world readable file is not recommended. A safer method is to use a credentials file instead, e.g. inside /etc/samba/credentials:


Replace username=myuser,password=mypass with credentials=/etc/samba/credentials/share.

The credential file should explicitly readable/writeable to root:

# chown root:root /etc/samba/credentials
# chmod 700 /etc/samba/credentials
# chmod 600 /etc/samba/credentials/share

Automatic mounting


As mount entry

This is a simple example of a cifs mount entry that requires authentication:

Tip: Use x-systemd.automount if you want them to be mounted only upon access. See Fstab#Remote filesystem for details.

As systemd unit

Create a new .mount file inside /etc/systemd/system, e.g. mnt-myshare.mount. See systemd.mount(5) for details.


What= path to share

Where= path to mount the share

Options= share mounting options

  • Network mount units automatically acquire After dependencies on, and, and gain a Before dependency on unless nofail mount option is set. Towards the latter a Wants unit is added as well.
  • Append noauto to Options preventing automatically mount during boot (unless it is pulled in by some other unit).
  • If you want to use a hostname for the server you want to share (instead of an IP address), add to After and Wants. This might avoid mount errors at boot time that do not arise when testing the unit.
Description=Mount Share at boot


Tip: In case of an unreachable system, append ForceUnmount=true to [Mount], allowing the share to be (force-)unmounted.





$ smbtree -U remote_user


domain master = auto

Now restart smb.service and nmb.service.


Then, add the following line to /etc/fuse.conf:



$ cp -a /etc/smbnetfs/.smb ~

Then create a link to smb.conf:



auth			"hostname" "username" "password"



free_space_size 1073741824

When you are done with the configuration, you need to run

$ chmod 600 ~/.smb/smbnetfs.*

Otherwise, smbnetfs complains about 'insecure config file permissions'.


$ smbnetfs mount_point





File manager configuration

GNOME Files, Nemo, Caja, Thunar and PCManFM







name resolve order = lmhosts bcast host wins

as shown in this page.

Other graphical environments


  • pyneighborhood is available in the official repositories.

Tips and tricks

Discovering network shares


1. First, install the nmap and smbclient packages.

2. nmap checks which ports are open:

# nmap -p 139 -sT "192.168.1.*"


$ nmap -sT "192.168.1.*"
Interesting ports on
139/tcp  open  netbios-ssn
5000/tcp open  UPnP

Interesting ports on
6000/tcp open  X11




$ nmblookup -A
Looking up status of
        PUTER           <00> -         B <ACTIVE>
        HOMENET         <00> - <GROUP> B <ACTIVE>
        PUTER           <03> -         B <ACTIVE>
        PUTER           <20> -         B <ACTIVE>
        HOMENET         <1e> - <GROUP> B <ACTIVE>
        USERNAME        <03> -         B <ACTIVE>
        HOMENET         <1d> -         B <ACTIVE>
        MSBROWSE        <01> - <GROUP> B <ACTIVE>



$ smbclient -L \\PUTER
Sharename       Type      Comment

---- ------- MY_MUSIC Disk SHAREDDOCS Disk PRINTER$ Disk PRINTER Printer IPC$ IPC Remote Inter Process Communication Server Comment
------- PUTER Workgroup Master

Remote control of Windows computer


Send shutdown command with a comment:



Stop and start services:


To see all possible net rpc command:

$ net rpc


Failed to start Samba SMB/CIFS server

Possible solutions:

  • Check smb.conf on syntactic errors with testparm(1).
  • Set correct permissions for /var/cache/samba/ and restart smb.service:
# chmod 0755 /var/cache/samba/msg

Permission issues on AppArmor

If using a share path located outside of a home-directory, whitelist it in /etc/apparmor.d/local/usr.sbin.smbd. E.g.:

"/data/" rk,
"/data/**" lrwk,

No dialect specified on mount

The client is using an unsupported SMB/CIFS version that is required by the server.

See #Restrict protocols for better security for more information.

Unable to overwrite files, permissions errors


Reason: An user should set/check for server/client permissions, instead of using incorrect/possible insecure flags. (Discuss in Talk:Samba#)

Possible solutions:




map to guest = Bad User






Do one of the following for the settings to take effect:

  • Restart Windows
  • Restart the Server service via services.msc

Original article.





Error: Failed to retrieve printer list: NT_STATUS_UNSUCCESSFUL


  load printers = No
  printing = bsd
  printcap name = /dev/null
  disable spoolss = Yes


# cat /var/log/samba/smbd.log

and the error should now no longer be appearing.

Sharing a folder fails







to your iptables setup.

Protocol negotiation failed: NT_STATUS_INVALID_NETWORK_RESPONSE


Another problem could be, that the client uses an invalid protocol version. To check this try to connect with the smbclient where you specify the maximum protocol version manually:

$ smbclient -U <user name> -L //<server name> -m <protocol version: e. g. SMB2> -W <domain name>

If the command was successful then create a configuration file:

  workgroup = <domain name>
  client max protocol = SMB2

Connection to SERVER failed: (Error NT_STATUS_UNSUCCESSFUL)

You are probably passing a wrong server name to smbclient. To find out the server name, run hostnamectl on the server and look at "Transient hostname" line



Protocol negotiation failed: NT_STATUS_CONNECTION_RESET


Password Error when correct credentials are given (error 1326)



  lanman auth = yes
  ntlm auth = yes


  sec = ntlmv2
  client ntlmv2 auth = yes




Mapping reserved Windows characters


Possible solutions are:

  • Use the undocumented nomapposix mount option for cifs
  vfs objects = catia fruit
  fruit:encoding = native
  • Manually remap forbidden characters using catia
  vfs objects = catia


Folder shared inside graphical environment is not available to guests

This section presupposes:

  1. Usershares are configured following previous section
  3. Guests access has been set to shared folder during creation


  • Shared folder name is MySharedFiles
  • Guest access is read-only.
  • Windows users will access shared folder content without login prompt

Verify correct samba configuration


$ testparm

Verify correct shared folder creation

Run the following commands from a terminal:

$ cd /var/lib/samba/usershare
$ ls

If everything is fine, you will notice a file named mysharedfiles

Read the file contents using the following command:

$ cat mysharedfiles

The terminal output should display something like this:


Verify folder access by guest


$ smbclient -L localhost

If everything is fine, MySharedFiles should be displayed under Sharename column


$ smbclient -N //localhost/MySharedFiles

If everything is fine samba client prompt will be displayed:

smb: \>

From samba prompt verify guest can list directory contents:

smb: \> ls



# cd /home
# chmod -R 755 /home/yourUser/Shared


Mount error: Host is down


See also