I would like to restore LightDM to its default state, because for some reason
/etc/lightdm/unity-greeter.conf
is now an empty file.
Deleting /etc/lightdm/unity-greeter.conf
and then running sudo apt-get install --reinstall unity-greeter
doesn't create a new config file as you might expect.
How can I restore a missing config file?
Find out what package installed the config file:
As you can see, the name of the package is
unity-greeter
.If you deleted a directory, like
/etc/pam.d
, you can list every package that added to it by using the directory path:Run the following command, replacing
<package-name>
with the name of the package:And for restoring the directory:
If everything worked as expected, you should get a message:
A Practical example when needing to reinstall all of the PulseAudio configuration files:
For many cases, the default configuration file is provided by a package directly. In such cases, you can extract the specific file from the package, thus easily recovering the file.
To check if a package provides the file, run
dpkg -S
on the full path of the file. For example:Provided by a package
As we can see,
/etc/ssh/sshd_config
is not directly provided by any package, but the other two are provided byopenssh-client
andsudo
respectively. So, if you wished to recover/etc/ssh/ssh_config
, first get the package:Now, you can either extract the file directly to its intended location, or to its intended location relative to the current directory instead of
/
, if you wished to compare and contrast, or manually merge them or something. For the former:The
-C /
tellstar
to extract after changing to/
, which means the target file will get replaced. If you remove it,tar
will extract to the current directory, meaning./etc/ssh/ssh_config
will exist in your current directory.If for some reason
sudo
doesn't work, usepkexec
instead. Ifpkexec
doesn't work either, reboot to recovery mode, mount/
asrw
. If that doesn't work...Created by a package
What about
/etc/ssh/sshd_config
? It doesn't seem to be provided by any package, so how did it appear?In this case (and in many other such cases, another example being
/etc/modules
), the file was created using a package maintainer script while installation. This is often done when the configuration file needs to be changed due to user responses to queries. OpenSSH, for example, asks ifPermitRootLogin
should be changed tono
, in newer versions, among other things.To identify such cases, try greping through the maintainer scripts. Typically you would only need to look
postinst
, but if you don't have any luck withpostinst
, trypreinst
as well:In this case, we're in luck:
Only one file matched, and as luck would have it, it contains code to create a default configuration file:
Typically, this is what you would see (another example,
/etc/modules
fromkmod
):So, you can look for this code and get the contents from the script directly.
No such script? You can still try poking through the filelists of related packages to see if anything hits, but at this point, I see no easily generalizable method (short of reinstallation on transient environments, like a chroot or a VM or a live USB).
In the long run, keep your configuration under version control. Any VCS worth its salt can save the day here, and the
etckeeper
utility considerably simplifies the task of keeping/etc
in a VCS.Find the package that owns the configuration file:
it will outputs something similar to:
so the package name is "unity-greeter", download the package:
then extract its file system tree data to a tar file:
finally extract only that exact configuration anywhere you want it to be:
./etc/lightdm/unity-greeter.conf
is the file name in our archive./etc/lightdm/unity-greeter.conf
is where I'm sending it to be stored.Or as @Muru suggested, we can do it in one liner:
According to this thread on the Ubuntu Forums, it's as simple as running the following in a terminal:
I had the same Problem on Ubuntu 17.04. The postinstall uses a template from
/usr/share/openssh/
. It checks if rootlogin is enabled or not, sets this option and copies it to/etc/ssh
. After that it does some ucf and ucfr calls (I don't know what that is for).Just copy
/usr/share/openssh/sshd_config
to/etc/ssh/sshd_config
:Now adjust your
sshd_config
as you want.Delete (back) the file and and reinstall
unity-greeter
withapt-get install --reinstall unity-greeter
.This doesn't work all configuration files. For
/etc/nsswitch.conf
, see How to restore/recreate etc/nsswitch.conf files . It does not seem to be possible to reconstruct that file withdpkg-reconfigure
.