How do I get back the default Samba configuration file (Debian-based system)?

10

1

I recently installed Samba and I messed up the /etc/samba/smb.conf file. How do I get the original configuration back?

Frew Schmidt

Posted 2009-11-11T15:28:07.517

Reputation: 1 062

1sudo cp /usr/share/samba/smb.conf /etc/samba/smb.conf – ThorSummoner – 2017-11-18T06:13:08.893

Answers

1

The best way (gotten from #ubuntu) is to do this:

dpkg-reconfigure <package>

In this case that means

dpkg-reconfigure samba-common

Frew Schmidt

Posted 2009-11-11T15:28:07.517

Reputation: 1 062

8

Edited:

Spotted this on a serverfault question. If the dpkg-reconfigure foo doesn't work, use this:

  1. Remove or rename the broken configuration file.

    sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.broken
    
  2. 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.

quack quixote

Posted 2009-11-11T15:28:07.517

Reputation: 37 382

That flag only forces dpkg to overwrite the config file if it would otherwise have asked for permission to do so. It does not make it magically recreate pristine config files from the package. – Teddy – 2009-12-10T13:41:00.820

i believe you're right. ok, so you do want the --force-confmiss instead. in this particular case, eg samba, i think --force-confnew would perform the overwrite, but you're right that it's dependent on the particulars of the package configuration scripts. – quack quixote – 2009-12-10T13:55:12.023

7

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:

  1. 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 always foo.~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.

  2. 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.

  3. Purge and reinstall the package (with apt-get purge packagename followed by apt-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.

  4. 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.

  5. 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.

Teddy

Posted 2009-11-11T15:28:07.517

Reputation: 5 504

This should be higher. For me it was just a case of doing sudo cp /usr/share/samba/smb.conf /etc/samba/smb.conf to overwrite my trashed conf file with the original. – edzillion – 2015-08-12T13:31:35.800

2

dpkg-reconfigure <package> will not modify changed conf files by default.

Probably the easiest way to do this, if you still have the package in the apt cache is to run

dpgk -i --force-confask /var/cache/apt/archives/<package file name>

where the package file name is usually something like <package name>_<version>.deb (just use tab completion). This will run through the same process as an apt-upgrade, and ask you what you want to do when ever it finds a changed conf file. Just enter N at every prompt. dpkg will install the package version of the conf file with .dpkg-dist at the end of the file name. You can then use vimdiff or some other merge tool to compare differences, and modify the read conf file.

naught101

Posted 2009-11-11T15:28:07.517

Reputation: 911

1

You can extract the deb and grab the original file:

ar p packagename.deb data.tar.gz | tar zx

John T

Posted 2009-11-11T15:28:07.517

Reputation: 149 037

Using dpkg-source is easier, and using apt-get source PACKAGE is much easier. – Teddy – 2009-12-10T13:45:57.847

1@Teddy: only if the default config file is included in the source package to begin with. many packages install a heavily vendor-specific config file; some auto-generate their config files in the packagename.postinst script. – quack quixote – 2009-12-11T03:10:00.960

1

You can redownload and extract the contents of the deb package

Mahmoud Hossam

Posted 2009-11-11T15:28:07.517

Reputation: 1 070

1This is way too low level of a way to do it – Frew Schmidt – 2009-11-11T16:10:52.377

4doesn't mean it wont work – John T – 2009-11-11T16:12:21.017

1

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.

Totor

Posted 2009-11-11T15:28:07.517

Reputation: 1 100

Thanks for supplying the name of the package that contains this file. "sudo aptitude purge samba-common; sudo aptitude install samba" was my choice, but Totor's answer looks the least scary and most Debian of the choices. – Martin Dorey – 2016-04-15T00:29:50.963

-1

$ sudo cp /usr/share/samba/smb.conf /etc/samba/smb.conf

and

$ sudo dpkg --configure -a

will do the job.

Kushagra Karira

Posted 2009-11-11T15:28:07.517

Reputation: 1

This is nearly identical to all the other answers here. It's also on a post from '14. – var firstName – 2018-09-12T19:17:11.707