Using Same Pub Key on 2 VM

You do not need to copy the private key (the file on your computer) to the new VM. You only need to copy the Public Key (the "Lock").
Since Computer 1 and Computer 2 already hold the same Private Key, you only need to perform this setup once (from Computer 1). Once the new VM has the Public Key, both computers will automatically be able to log in.
Step 1: Use Computer 1 to install the key
Since Computer 1 has the original .pub file, use it to set up the new VM.
Run this command on Computer 1:
Bash
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@NEW_VM_IP
(Replace user and NEW_VM_IP with your new VM's details.)
Step 2: Test from both computers
From Computer 1: Try
ssh user@NEW_VM_IP. It should work without a password.From Computer 2: Try
ssh user@NEW_VM_IP.It will work instantly. You do not need to do anything on Computer 2.
Why? Because Computer 2 has the same "Key" in its pocket. You just installed the matching "Lock" on the new VM.
Alternative: What if I am currently on Computer 2?
If you are sitting at Computer 2 and want to set up the new VM from there, you might be missing the .pub file (since we only copied the private key earlier).
You can regenerate the Public Key from your Private Key using this command on Computer 2:
Generate the missing Public Key file:
Bash
ssh-keygen -y -f ~/.ssh/id_ed25519 > ~/.ssh/id_ed25519.pubNow copy it to the new VM:
Bash
ssh-copy-id -i ~/.ssh/id_ed25519.pub user@NEW_VM_IP
Summary of the Setup
Computer 1 & 2: Both hold the Private Key (Identity).
All VMs: All hold the Public Key (Authorized List).
Would you like to know how to set up an "SSH Alias" so you can just type ssh vm2 instead of the IP address?




