How do I get back the default Samba configuration file (Debian-based system)?
Short answer: /usr/share/samba/smb.conf
is the original version of the smb.conf file.
When faced with this situation for any package, what I do is one of the following:
Check for backup files of the original version from your editor. I use Emacs, which normally leaves
foo~
files, and I've set the numerical version-control option so the original version is alwaysfoo.~1~
. But maybe you did it some other way, or used some other editor. Consider checking your editor's configuration to turn this feature on if you haven't already; it's a good habit to get into.Reconfigure the package with
dpkg-reconfigure PACKAGENAME
. Sometimes this does the trick. In my experience it rarely works; it depends on how the package is creating its configuration files.Purge and reinstall the package (with
apt-get purge packagename
followed byapt-get install packagename
). This should always work.
In extreme cases you have to, after purging, manually hunt down and delete the config files before reinstalling the package, but this is rare. However, this will eliminate any other data and/or config files for the package, and that is not always acceptable.Download the source code for the package (
apt-get source foo
) and see if the original config file exist as a file there. However, it may be that the config file does not exist beforehand, but is created at installation by the package's post-install script.Check the postinst script for the package (
/var/lib/dpkg/info/foo.postinst
) to find out where it creates the config file and how it does it. Then try to repeat the process manually. This is a bit of work, and not always easy.
Edited:
Spotted this on a serverfault question. If the dpkg-reconfigure foo
doesn't work, use this:
Remove or rename the broken configuration file.
sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.broken
Request replacements from
dpkg
.sudo dpkg -i --force-confmiss /path/to/samba-common.deb
This tells dpkg
to replace missing configuration files with those from the .deb. You might find the original package .deb in /var/cache/apt/archives
, or you can use a fresh copy of the same version from your distribution's repositories.
dpkg -i --force-confnew foo.deb
This tells dpkg
to overwrite existing configuration files with those from the .deb. You might find the original package .deb in /var/cache/apt/archives
, or you can use a fresh copy of the same version from your distribution's repositories.
You can restore the original smb.conf
configuration file like this:
# cp /usr/share/samba/smb.conf /etc/samba/smb.conf
# dpkg-reconfigure samba-common
This is basically what the original package installation process does (on Debian Squeeze).
This will overwrite you current smb.conf
, so make a backup first if you don't want to lose it.