Search code examples
sshssh-keysopenssh

Change SSH pem file


I want to change my remote server SSH. Currently I login through a .pem file

ssh -l ubuntu -i .ssh/myfile.pem XX.XX.XXX.XXX

I tried to find how to change that access key but I found only that methor :

ssh-keygen -t rsa -b 2048
cp id_rsa.pub authorised_keys 
scp authorized_keys [email protected]:/home/ubuntu/.ssh

I see no .pem file generated, plus how can I connect now ? I want to make sure before I do anything so I don't lose ability to connect via SSH. Should I remove the old key with :

ssh-keygen -R hostname

If yes, when ? after or before the scp ? if after this will remove both keys, if before then I wouldn't be able to perform scp !!! I am a bot confused. I see no .pem file in my remote, the pem file is only in my local .ssh folder. in remote .ssh I see :

enter image description here


Solution

  • With "ssh-keygen" command you generate a pair of public and private keys (by default stored in $HOME/.ssh).

    Then you copy the public key in your remote server, and the private key in your local client (with permissions 0600). You can use "ssh-add" command to add the private key to the authentication agent to be able to connect to the remote server.