I'm changing between computers.
On an old one I have SSH keys (to remote servers, AWS, etc...)
Is it considered to be a good practice just to copy the .ssh folder to a new computer ?
If not, what is a proper way to handle it ?
Yes, if you change the machine from which you access your servers, you can just copy the ~/.ssh directory from the old machine to the new one. It is unnecessary (and cumbersome) to generate a new key pair for every server. You just need the private keys on your new machine.
Remember that ~/.ssh contains sensitive data (private keys), so transfer it via a secure medium (SCP or a USB drive, for instance; not via e-mail!). Also, be sure to dispose of the private keys stored on the old machine.
No - it's not considered best practice to copy your ~/.ssh folder to a new computer. Instead, on your new computer, create your ~/.ssh folder from scratch using:
$ ssh-keygen followed up by:
$ ssh-copy-id username@remote_host to copy your public key to each of your ssh server hosts.
There's a good tutorial covering some rare contingencies here. Once you're ready to permanently sideline your old computer, be sure to remove the contents of its ~/.ssh folder.
If you prefer to copy your entire ~/.ssh folder from your old machine to your new one, you can do this in some situations. Simply copy the entire ~/.ssh folder on your old machine to a USB drive. Once that's been done move the USB drive to the new machine, mount it, and copy its contents to the ~/.ssh folder on the new computer using the cp -a command to preserve proper permissions; something like this:
$ cp -a /mnt/myusb/.ssh/. ~/.ssh/ ssh-copy-id -i <keyfile> user@host I strongly disagree with the answer by Seamus. Yes, it is good practice to replace your keys at appropriate intervals. Tying that to when you replace your hardware is usually not a good idea. You have enough things to worry about without losing all your remote access. It also won't be possible to use ssh-copy-id from the new computer unless you also allow password based authentication (which undermines most of the reasons for using key pair auth in the first place).
If you manage the servers for a multi-national bank or launch codes for ICBMs then you do need to think about the risks of your keys being recovered from your discarded hardware even after you securely erased the files. But for the rest of us, shred or secure-delete is sufficient.