In order to login securely to a remote system via a secure shell, a private key/public key pair is generated. The private key is stored on the local machine. The public key is stored on the target machine in the
$HOME/.ssh/authorized_keysfile. Public keys are not sensitive information and may be known to anybody, whereas the private key needs to be protected very carefully by a strong passphrase. Using multiple servers is easier by using ssh agent.
ssh-agentremembers the passphrase so that the user does not need to type it every time he or she wants to connect or send data to the server.
Create the identiy-key pair:
cd ~/.ssh ssh-keygen
Copy the public key to the remote server:
scp ~/.ssh/id_rsa.pub email@example.com:pubkey.txt ssh firstname.lastname@example.org mkdir ~/.ssh chmod 700 .ssh cat pubkey.txt >> ~/.ssh/authorized_keys rm ~/pubkey.txt chmod 600 ~/.ssh/* exit
Test the remote public key:
Start the ssh-agent:
Add your private key to the agent's cache:
Test the connection again:
ssh email@example.com exit