SSH authentication using public keys can be achieved in two steps:
- create a public and private key pair on client side, and
- copy your public key to server.
The command ssh-keygen allows us to generate and manage authentication keys. To generate a pair of RSA keys, we use:
ssh-keygen -t rsa
It generates a pair of RSA keys and saves them in directory $HOME/.ssh; the default name for public (private) key is id_rsa.pub (id_rsa). Always use passphrases to protect your private keys.
Public keys are not sensitive data in general, we may choose any method to copy them. However, command ssh-copy-id provides an easy way to accomplish this. You use:
ssh-copy-id user@server
to copy your public key to server. After that, your public key file will be copied/appended to file $HOME/.ssh/authorized_keys in server. Don't forget to specify (option -i) the path of your public key file if it is not in $HOME/.ssh/id_rsa.pub on client side.
An ssh-agent is very helpful in using public keys for SSH authentication; it is strongly recommended.
No comments:
Post a Comment