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

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

$ 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

$ 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 :)

Written by

DevOps engineer, loves Linux, Python, cats and Amiga computers

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store