10

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?

15

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.

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

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

Try :

sudo dpkg-reconfigure openssh-server
  • 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 Stokes Jun 19 '20 at 20:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.