How To: Ubuntu / Debian Linux Regenerate OpenSSH Host Keys

How To: Ubuntu / Debian Linux Regenerate OpenSSH Host Keys

To regenerate OpenSSH host keys on an Ubuntu or Debian Linux system, you can follow these steps:

  1. Stop the OpenSSH server: Before regenerating the host keys, you will need to stop the OpenSSH server. You can do this by running the following command:
systemctl stop ssh
Sourc‮ual.www:e‬tturi.com
  1. Remove the existing host keys: Next, you will need to remove the existing host keys. These are typically stored in the /etc/ssh directory. You can remove the host keys by running the following commands:
rm /etc/ssh/ssh_host_*
  1. Regenerate the host keys: To regenerate the host keys, you can use the dpkg-reconfigure command followed by the openssh-server package. For example:
dpkg-reconfigure openssh-server

This will run the OpenSSH key generation script and create new host keys.

  1. Start the OpenSSH server: After regenerating the host keys, you will need to start the OpenSSH server again. You can do this by running the following command:
systemctl start ssh
  1. Test the connection: Finally, you can test the connection to the OpenSSH server to make sure that everything is working as expected. You can do this by running the ssh command and connecting to the server.

For example:

ssh username@server

Replace username with your username and server with the hostname or IP address of the server. If the connection is successful, you will be logged in to the server.

It's important to note that regenerating the host keys will invalidate any existing SSH connections to the server. All users will need to establish new connections to the server after the host keys have been regenerated.

Created Time:2017-10-29 22:08:35  Author:lautturi