You fucked up your configuration files without a backup? — how to restore them.

There is no need to hide the shame.. this is something that we all have done! we have messed with a configuration file so much that the…

Note that this example will restore the original configuration files from the package, not the last good changes you might had done to your files.

There is no need to hide the shame.. this is something that we all have done! we have messed with a configuration file so much that the service could not start! and even worse: “we didn't took a backup before we start editing”.

Apparently there is a very easy solution on this and its not to uninstall-install again the program, but there is the option to restore only files we want.

The procedure is very simple and its a two steps procedure.

1. Find the software package of the file

We need to find the software that holds the original file that we want to restore, to do this:$ dpkg -S <path-with-file>

In my case was the ssh_config file:$ dpkg -S /etc/ssh/ssh_config

It outputs that the package is openssh-client

2. Restore the file

The bellow command for each configuration file of the package if you want to replace it with the original$ sudo apt install --reinstall -o Dpkg::Options::="--force-confask" openssh-clientkpatronas@nostromo:~$ sudo apt install --reinstall -o Dpkg::Options::="--force-confask" openssh-client
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following packages were automatically installed and are no longer required:
 libnet-proxy-perl libvte-common libvte9
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 1 reinstalled, 0 to remove and 10 not upgraded.
Need to get 0 B/672 kB of archives.
After this operation, 0 B of additional disk space will be used.
(Reading database ... 235374 files and directories currently installed.)
Preparing to unpack .../openssh-client_1%3a8.2p1-4ubuntu0.1_amd64.deb ...
Unpacking openssh-client (1:8.2p1-4ubuntu0.1) over (1:8.2p1-4ubuntu0.1) ...
Setting up openssh-client (1:8.2p1-4ubuntu0.1) ...Configuration file '/etc/ssh/ssh_config'
==> Modified (by you or by a script) since installation.
    Version in package is the same as at last installation.
  What would you like to do about it ?  Your options are:
   Y or I  : install the package maintainer's version
   N or O  : keep your currently-installed version
     D     : show the differences between the versions
     Z     : start a shell to examine the situation
The default action is to keep your current version.
*** ssh_config (Y/I/N/O/D/Z) [default=N] ? Y
Installing new version of config file /etc/ssh/ssh_config ...
Processing triggers for man-db (2.9.1-1) ...

Options explanation:

  • confask: If a conffile has been modified always offer to replace it with the version in the package, even if the version in the package did not change.

I hope you found this article useful :)