Test your Samba server for configuration errors using testparm

Linux and Unix Test your Samba server for configuration errors using testparm
You can easily test your Samba server for configuration errors. It check an smb.conf configuration file for internal correctness. If this program reports no problems, you can use the configuration file with confidence that smbd will successfully load the configuration file.

Open a shell prompt and then type the following command:
# testparm
# testparm /etc/samba/smb.conf
We will see the following message on screen:

Load smb config files from /usr/local/etc/smb4.conf Loaded services file OK. Server role: ROLE_STANDALONE Press enter to see a dump of your service definitions

If you hit the [Enter], key you will see other details as follows:

# Global parameters
	aio max threads = 2
	bind interfaces only = Yes
	disable spoolss = Yes
	dns proxy = No
	enable web service discovery = Yes
	interfaces =
	kernel change notify = No
	load printers = No
	logging = file
	max log size = 51200
	nsupdate command = /usr/local/bin/samba-nsupdate -g
	registry shares = Yes
	restrict anonymous = 2
	server role = standalone server
	server string = My Samba Server At Home
	unix extensions = No
	idmap config *: range = 90000001-100000000
	idmap config * : backend = tdb
	directory name cache size = 0
	dos filemode = Yes

The program will issue a message saying whether the configuration file loaded OK or not. This message may be preceded by errors and warnings if the file did not load. If the file was loaded OK, the program then dumps all known service details to screen as shown above.

Test your Samba server for configuration errors with a simple shell script

If the testparm command finds an error in the smb.conf file it returns an exit code of 1 to the calling program, else it returns an exit code of 0. This allows shell scripts to test the output from testparm. For example:

if [ $? -eq 0 ]; then
 echo "Syntax OK"
 echo "Syntax Error"

Setting up debug level

Pass the -d option as follows:
# testparm -d value
# testparm -d 5

The value is an integer from 0 to 10. The default value if this parameter is not specified is 1. The higher this value, the more detail will be logged to the log files about the activities of the server. At value 0, only critical errors and serious warnings will be logged. Value 1 is a reasonable level for day-to-day running – it generates a small amount of information about operations carried out.

How to skip the global checks

Try passing the following -l option:
# testparm -l

Verbose option

The testparm command will also output all options that were not used in smb.conf and are thus set to their defaults. The syntax is:
# testparm -v
# testparm v | more


You learned how to use the testparm command check an smb.conf configuration file for internal correctness and errors using the command-line options on Linux, FreeBSD, OpenBSD, netBSD and Unix-like systems. See the following tutorials too:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 5 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
5 comments… add one
  • ken Jul 5, 2007 @ 5:38

    That’s extremely OK!

  • oes tsetnoc Sep 28, 2009 @ 2:15

    well when i tried to configure smba – everything went fine … but when clicked on the icon of UNIX SERVER from WIN xp – got an error stating that I do not have access permission and shld contact administartor of that server ..

  • stainless Dec 24, 2011 @ 20:23

    Doesn’t testparm have to be function? to wrk like that?

    function testparm()
    if [ $? -eq 0 ]; then
     echo "Syntax OK"
     echo "Syntax Error"
    • Lucas Oct 22, 2012 @ 9:32

      No. The $? variable stores the value returned by last program executed, in this case, testparm.

      Try running any program, including one that quit with errors, and then do an echo $? to see the exit code.

  • Matthew Setter Oct 16, 2020 @ 20:23

    You could also use the following to test the configuration:

    testparm -s 2>1 1>/dev/null && echo "ok" || echo "not ok"

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum