Skip to content

Instantly share code, notes, and snippets.

@meetnick
Last active March 14, 2025 01:37
Show Gist options
  • Save meetnick/fb5587d25d4174d7adbc8a1ded642d3c to your computer and use it in GitHub Desktop.
Save meetnick/fb5587d25d4174d7adbc8a1ded642d3c to your computer and use it in GitHub Desktop.
Add support to .conf files individually in samba
#!/bin/sh
# default samba .conf file
SMB_CONF=/etc/samba/smb.conf
# samba directory to store samba configuration files individually
SMB_CONF_DIR=/etc/samba/smb.conf.d/
# first need to create individual .conf files with desired sambs configuration into path defined above
# file which contains all includes to samba configuration files individually
SMB_INCLUDES=/etc/samba/includes.conf
# adds includes.conf file existance to smb.conf file
if ! grep -q 'include = '"${SMB_INCLUDES}" $SMB_CONF ; then
echo 'include = '"${SMB_INCLUDES}" | tee -a $SMB_CONF > /dev/null
fi
# create directory smb.conf.d to store samba .conf files
mkdir -p $SMB_CONF_DIR
# populates includes.conf with files in smb.conf.d directory
ls "${SMB_CONF_DIR}"* | sed -e 's/^/include = /' > $SMB_INCLUDES
@meetnick
Copy link
Author

Usage

The above gist account that you have already conf files into directory /etc/samba/smb.conf.d.

  • first, be sure you have samba conf files inside /etc/samba/smb.conf.d/, such as:

/etc/samba/smb.conf.d/example.conf

[example]  
  path = /home/user/Public  
  comment = Shared description  
  writable = yes  
  guest ok = yes  
  browseable = yes  

Note: you can choose other conf files directory by changing env variable SMB_CONF_DIR.

The Gist automates the following:

  • Now we must add the previously created conf file into our includes.conf file, located into /etc/samba/includes.conf:
    include = /etc/samba/smb.conf.d/example.conf

Note: more entry must be appended (if needed) into includes.conf file.

  • Now we add our include file into smb.conf file:
    include = /etc/samba/includes.conf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment