Congratulations on getting out of that precarious situation, Emily!
The SSH should be a personal identifier of each system separately, so if you simply try to copy the other key over, unless all accounts (and hostname) are identical, you’ll encounter a validation error.
The best way is to go to the terminal and execute:
ssh-keygen
– for your new system.
Since you’ve completed the VPN setup and the security aspects of your VPS, installing new SSH keys on it will require a bit of a process. However, you do not need to do it just to gain VPN access, unless you wish to control your VPS from another computer. For the VPN, you simply generate a new configuration file for your new computer.
If you need to access your VPS from another system, the process is the following (you can repeat that for any new system):
What you will need is to go to your VPS provider and use their web terminal to login as root. Once you do that, execute:
nano /etc/ssh/sshd_config
Navigate to PasswordAuthentication and set it to yes.
Press CTRL+O and then Enter to save. Then hit CTRL+X to exit.
Once back in terminal, execute:
systemctl restart sshd
This will allow the new SSH keys to be copied to your VPS from the new system. Exit the terminal via the exit
command. Then, go to the terminal of your new system and type in:
ssh-copy-id username@x.x.x.x
Where username is your non-root actual username on the VPS, and x.x.x.x is your VPS’ IP address.
Once you hit enter, it will ask you for your VPS user’s password (which is why we re-enabled it on the SSH configuration).
Once it is done, it means that your new computer’s key has been added to the VPS.
Then test the connection by typing:
ssh username@x.x.x.x
– from your new system.
Once you’re logged in, type in:
sudo su
nano /etc/ssh/sshd_config
Navigate to the PasswordAuthentication again and set it back to no. CTRL+O then Enter to save. CTRL+X to exit. Once you exit, execute:
systemctl restart sshd
exit
This will exit root mode and you can type in another exit
to completely disconnect from your VPS.
And with that, you’re all set!