Friday, March 20, 2015

How to manually generate your SSH Key in Mac OS X?!

  • Open the Mac OS X Terminal
  • (Finder > Applications > Utilities)
  • Double-click the Terminal application
  • The Terminal window opens with the command line prompt displaying the name of your machine and your username.

How to generate a SSH Key?

SSH key consists of a pair of files. One is the private key (which you should keep to your self. Do not share this key with anyone!) and the other is the public key (this will be used to log into other machines).
  • To start the key generation process        
                  ssh-keygen -t rsa
  • When you execute this command, the ssh-keygen utility prompts you to indicate where to store the key.
  • Press the Enter to accept the default location.
  • The ssh-keygen utility prompts you for a passphrase. (Here you can skip the step by pressing Enter without giving a passphrase)
    After you confirm the passphrase, the system generates the key pair.
  • Your identification has been saved in key.txt.
  • Your public key has been saved in key.txt.pub.
  • The key fingerprint will be shown as bellow :

7d:4d:bb:5c:d1:45:01:ae:a3:19:ff:7b:dd:8c:28:b3 NAME@MAC.local
The key's randomart image is:
+--[ RSA 2048]----+
|                        ..o+|
|                        .   o|
|                          ....|
|                     .  .o ..|
|                  S..o. o .|
|                     =... o |
|                  o . .ooo|
|                    o o ..+|
|                   E+ oo  |
+---------------------+
  • Your private key is saved to the id_rsa file in the .ssh directory.
     
  • Your public key is saved to the id_rsa.pub file.
Using the Public Key

You have to give the public key to the server admin or the connection you are going to access.

Using the Private Key (Do not reveal this to anyone)
  • Open the file you keep the Private Key with the text editor. Name you file with a name you want. For this I am calling it privateKey.txt.
    Paste in the private key and save the file.
  • If you are using the terminal:    vim privateKey.txt
    When the empty file is opened, press i in your keyboard to get into insert mode, paste the key, press ESC and then :wq to write/save and exit from the open file.
  • After saving the file change the permissions to 600 or 400. (this is a must)
                           chmod 600 deployment_key.txt
  • Now log in using the SSH client. 
  • Load the key in file privateKey.txt to log in to the user (UserName) to IP (xxx.xxx.xx.xx)
                           ssh -i privateKey.txt UserName@xxx.xxx.xx.xx
  • Now you will be asked whether you are sure to connect. Type yes and press Enter.
    Then you will be asked to enter a password for your key (if you have one).
    After the step you will be logged in to the server.


No comments:

Post a Comment