How to generate ssh key?


Generate ssh key using ssh-keygen
Generate ssh key using ssh-keygen

In other to generate SSH key(s) follow the below steps,

  1. Open your command line Terminal (macOS/Linux)
  2. Type in the command:
    ssh-keygen -b 2048 -t rsa
  3. Enter the file in which to save the SSH key,
  4. Enter the passphase,
  5. Now you will be asked to enter the passphrase again,
  6. Your identification and the public key will now be saved.
Example:
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/c2c/.ssh/id_rsa): my_ssh_key
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in my_ssh_key
Your public key has been saved in my_ssh_key.pub
The key fingerprint is:

SHA256:iJcAJMGEjgc+2GC6uYJOXOtDWdD9iDwbTIA4XkWgQ+hg c2c@Desktop-MacBook-Pro.local

The key's randomart image is:
+---[RSA 2048]----+
|X=+.= =.         |
|=* = = .         |
|E+  * . o        |
|+Bo  X + .       |
|.+o.+ B S        |
|+ .o.o           |
|.+..             |
|= ..             |
|o. ..            |
+----[SHA256]-----+ 
See the contents of the SSH key
% ls -ltrh     
total 16
-rw-------  1 code2care  staff   1.9K Aug 15 14:41 my_ssh_key
-rw-r--r--  1 code2care  staff   420B Aug 15 14:41 my_ssh_key.pub
% cat my_ssh_key
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAACmFlczI1Ni1jdHICCCAGYmNyeXB0AAAAGAAAABA6v8bbGe
ZgN9GJjTTsbUFTAAAAEAAXYAEAAAEXAAAAB3NzaC1yc2EAAAADAQABAAABAQC+OaD8KXs4
X+sHrq9w9c/cnsLmj9lh7vq9Ck1P1kOvwuFT72bkdLcW7//sIx9Cjz2RHKlTwaVhLKozO8
JFlMpb2EGNl3trRA0vFs/3RVZRAJqwMbqslough7X4/kltH2qOjiFqGdJPOo6+ewJQtnC9
3TggpDvXeBB5Funm5LqBPSVfrITVfHv39Z1xu1ja4JQFnXV3BAInAvrp8AKO0RMOOF/MCi
KyrE8AlOzlksNRI0aalvpWGfPLjsnyvoWOWckgc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A
prt4XLVvrPZXLjFAixjWhjPxkqDTtSx3jzqI0cEvC8NNshf+dkGJBOSCPvN8pHhlJVc+I5
Ocf7WY0KGAlbalcH3Kejl6cKluPowcIe6YugnhvmwmtxPrhclyA3qk4kCjuI258OcbEBdZ
LWN6nX7ByNtw24afITe8u4dNxTBK2pEGq88e/pJNzwfaoZq9PB1jBtjmSNxJltJ1k1gFmI
wIsRMcSzfRQCtTVTRaVmgd6z4MJhwTrAqoQ0WZh0Oa6z2VQfM/ubo61nIa5sGsjPuC8OWZ
uvZgeWx9eFZ8ZoEKaKBdgkoNjwiN1QfG/suF6/4S3WCTVUXM3o
-----END OPENSSH PRIVATE KEY-----

% cat my_ssh_key.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABXYABAQC+OaD8KXs4X+sHrq9w9c/cnsLmj9lh7
vq9Ck1P1kOvwuFT72bkdLcW7//sIx9Cjz2RHKlTwaVhLKozO8JFlMpb2EGNl3trRA0vFs/3RV
ZRAJqwMbqslough7X4/kltH2qOjiFqGdJPOo6+ewJQtnC93TggpDvXeetq5Funm5LqBPSVfr
ITVfHv39Z1xu1ja4JQFnXV3BAInAvrp8AKO0RMOOF/MCiKyrE8AlOzlksNRI0aalvpWGfPLjsn
yvoWOWckgc77KKQlzxP5f+a65qGMtUrhgMOcd6s9APlA//hQFqlkoYaW2TtJoxn+uIP1D50
nP+s27nJGPA774kZT4e895 c2c@Desktop-MacBook-Air.local
Advertisements
Try Out Code2care Dev Tools:

Advertisements

Advertisements
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and software developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include learnings, tutorials, trouble-shooting steps, video tutorials, code snippets, how-to, blogs, articles, etc.

🎉 We are celebrating the 10th years of Code2care! Thank you for all your support!

We strongly support Gender Equality & Diversity.