How to access a cloned VirtualBox Ubuntu Server via SSH to get a different Address
I installed a headless Ubuntu server build on VirtualBox, and once I fully prepared it to work, I cloned it to have a second, exactly the same, instance. However, the clone shares it's CMD SSH access and since that happened, I cannot access it.
Edit: I cannot access it while the other is accessed at the same time. If I turn one off, the other works.
Is there any way to assign a new SSH key so I can access both servers on different cmds at the same time?
I very often do something similar where I install a new version of Ubuntu and keep that pristine version for cloning (which is a lot faster than re-installing each time).
- To create a clone, I stop that instance (
sudo init 0
). - Create the clone
- Boot the clone
- Edit the network setup of the clone
Since Ubuntu 18.04, I edit the netplan file, usually:
vim /etc/netplan/50-cloud-init.yaml
then assign a new address to the server and reboot to make sure it works as expected (especially, I also change the hostname and want to make sure it survives a reboot).
Once that works, I can start both servers in parallel since they now each have a different IP address.
You could also use DHCP because in that case each computer is automatically assigned an IP address. Only that can be complicated to setup other tools as one and/or the other IP may change without notice and you'd have to edit your setup (unless you can use a DNS to give each computer a name). The DHCP server also has an option to use the computer MAC address and force a specific IP for each specific computer. I often use that feature for external devices (however, the iPhone OS just change their code to dynamically change the MAC address on us... not sure how much more secure that can possibly be... since that way I can't verify who is connecting where if that's an iPhone!)
As for the SSH keys, you can simply put your key in your VPS accounts as you would normally do. The same key can be reused any number of times (i.e. put the public key in all your VPS ~/.ssh/authorized_keys
file).
If you'd like to directly connect between your VPS, you also need to copy the private key to said VPS. However, keep in mind that by default the VirtualBox servers appear on the Internet (unless you have a strong firewall setup). So placing your private keys in your VPS is not advised.