13

I accidentally deleted /etc/ssh/ssh_config file.

I've tried purging and re-installing openssh-server and ssh but the file doesn't return.

How would I restore this file?

0

3 Answers 3

18

The file /etc/ssh/ssh_config is part of the package openssh-client. Therefore

sudo apt-get purge openssh-client
sudo apt-get install openssh-client

or

sudo apt-get install --reinstall openssh-client

Purging the package ssh makes no sense, it's only a meta-package for openssh-client and openssh-server and purging this package doesn't purge openssh-client and openssh-server.

1
  • 1
    That's a bit drastic. Oct 6, 2015 at 14:02
8

Try :

sudo dpkg-reconfigure openssh-server
1
  • Thanks, and perhaps a sudo systemctrl restart sshd? Thanks very much, that done it. I selected install maintainers version so the file was updated but at least now I'm able to access from my local machine via ssh.
    – Michael
    Jun 19, 2020 at 20:16
8

The file /etc/ssh_config is a configuration file, which has special handling in dpkg, so it is preserved across package upgrades. If the file is deleted, this, too, is preserved, so merely reinstalling the package will not fix the problem.

Your choices are, to either

  • completely remove the package including its configuration files, as A.B. suggested, but this will remove all custom configuration for the package, or
  • reinstall the package by hand using dpkg, giving it the --force-confnew option to overwrite configuration files.

The latter option has the advantage of keeping other customized configuration files, renamed with a suffix of .dpkg-old.

To do this, you need a copy of the package file,

apt-get --download-only --reinstall install openssh-client

will download it to /var/cache/apt/archives, and

dpkg --force-confnew -i /var/cache/apt/archives/openssh-client_...

will install it (replace the ... with the version downloaded).

3
  • Ok, now I understand what you mean. Good job.
    – A.B.
    Oct 6, 2015 at 14:15
  • Why not just sudo apt-get download openssh-client?
    – heemayl
    Oct 7, 2015 at 6:05
  • 1
    Because I'm ancient, and that command was added later on, so I didn't know it yet. Oct 7, 2015 at 20:40

Not the answer you're looking for? Browse other questions tagged .