Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Can some one please tell me, for using SSH, why does a host also need to have a public and private key? And how can I generate a public/private key pair for myself?

share|improve this question
add comment

migrated from stackoverflow.com Nov 17 '10 at 16:43

This question came from our site for professional and enthusiast programmers.

5 Answers

up vote 5 down vote accepted

ssh-kegen(1)

You need the host key so you know you are connecting to the right server and not a fake one.

share|improve this answer
add comment

It differs from one distribution to another. On Ubuntu use this command:

ssh-keygen

It will generate two keys, one public (the one you will share to the server) and the other is private and you shall not share with anyone. Once the public key is copied in the ~/.ssh/authorized_keys in the server, you can login without being prompt for password.

share|improve this answer
add comment

Public/private keys are like locks and keys: the server sends you a lock, but keeps the key, and then you lock your messages to the server. You need to send the server a lock as well so you can retrieve that data.

Wikipedia has a great example of this.

share|improve this answer
add comment
# private key
openssl genrsa -out privkey.pem 2048

# public key
openssl rsa -in privkey.pem -pubout -out pubkey.pem

For more information:
http://www.openssl.org/docs/apps/rsa.html
http://www.openssl.org/docs/HOWTO/keys.txt

share|improve this answer
add comment

Anyway to generate keys you should use ssh-keygen. You need private and public keys to use SSL, an encryption system based on asymmetric keys.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.