LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 02-08-2024, 11:58 PM   #1
crypto7541
LQ Newbie
 
Registered: Dec 2020
Posts: 3

Rep: Reputation: Disabled
Generate new SSH Host keys


Hi,

After the fresh installation, and patching the server for the purpose of Virtual Template.
If I create a new VMs from this template, There will be same host keys for all virtual servers.

Can we create new keys for the template VM, so the new VM shall have different keys and how to generate the new keys for existing VMs that have duplicate keys.?


Thanks,
 
Old 02-09-2024, 03:00 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Have your VM creation script call ssh-keygen towards the end. From within the VM, the directory /etc/ssh/ will be used. Pre-existing SSH host keys have to be deleted, but be careful not to delete anything else.

Code:
ssh-keygen -a 17 -A
Again, don't run that inside your host, just inside the guest. If you have to run it from within the host, then mount the image and point to the relevant directory using the -f option:

Code:
ssh-keygen -a 17 -A -f /mnt
The -f would cause ssh-keygen to put the new host keys in /mnt/etc/ssh/

See "man ssh-keygen" about the -A option.

Which distro is this for, including version?
 
Old 02-09-2024, 05:00 AM   #3
crypto7541
LQ Newbie
 
Registered: Dec 2020
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank you for helping.

I am using Oracle Linux 8.8, after running the command and matched the values/content of the files it were same, so it seems that it didn't make any changes.
 
Old 02-09-2024, 05:03 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,328
Blog Entries: 3

Rep: Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726Reputation: 3726
Quote:
Originally Posted by crypto7541 View Post
I am using Oracle Linux 8.8, ...
Thanks.

As mentioned, you have to delete the old keys yourself. The -A option won't overwrite them.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to generate https cert for misskey using acme.sh cant find folders to generate hacknorris Linux - Server 7 11-14-2022 03:28 AM
Is there any ways to generate Encryption keys and storing the Key keys at Kernel space. pandiaraj88 Linux - Software 1 09-05-2022 06:17 AM
Re-generate ssh keys when password is changed for Service Accounts? JockVSJock Linux - Newbie 5 09-05-2017 09:17 PM
SSH host keys are not being read correctly from .ssh/known_hosts. bartonski Linux - Software 3 10-29-2009 04:40 PM
SSH host keys VS SSH keys kenneho Linux - Security 3 09-11-2008 06:03 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration