How to set up ssh keys

SSH keys are a pair of the private and the public keys. The private key is identity of a client and it must not be shared by anyone. The public key can be shared freely with any SSH server to which client would like to connect.

Here are the steps you need to follow to setup ssh key based authentication

1- Generate SSH key (client)

Running the commands below will create two files called id_rsa and in your .ssh dir. id_rsa is your private key and is your public key.

ssh-keygen -t rsa

or more specifically

ishtiaqmedsmbp2:.ssh Ishtiaq$ ssh-keygen -t rsa -b 1024 -C "$(whoami)@$(hostname)-$(date)"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/Ishtiaq/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/Ishtiaq/.ssh/id_rsa.
Your public key has been saved in /Users/Ishtiaq/.ssh/
The key fingerprint is:
a4:1b:aa:dd:44:2c:b3:78:88:03:3e:19:f4:86:53:11 Ishtiaq@ishtiaq-ahmeds-macbook-pro-2.local-Sun 20 Apr 2014 12:01:46 EST
The key's randomart image is:
+--[ RSA 1024]----+
|   E.            |
|    .            |
| . .    .        |
|. +  . o         |
|.+ oo = S        |
|o.=o * o         |
|o+o + o          |
| ..+ o           |
|  . . .          |

2- Copy public key to SSH server (client)

ishtiaqmedsmbp2:.ssh Ishtiaq$ scp ~/.ssh/
Identity added: /Users/Ishtiaq/.ssh/id_rsa (/Users/Ishtiaq/.ssh/id_rsa)'s password:                                                                                                                       100%  285     0.3KB/s   00:00

3- Add client’s public key to server’s authorized keys (server)

After running commands below, your ssh server would be ready to accept ssh connections from client without prompting for pssword

cat ~/ >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
rm -f ~/

 4- Test (client)


This time it didn’t ask you to enter password.



  1. very useful and easily understandable. Thanks for the sharing.
    Can you please elaborate the parameters details in “specific command”
    ssh Ishtiaq$ ssh-keygen -t rsa -b 1024 -C “$(whoami)@$(hostname)-$(date)”
    -b:? and so on

  2. -t : type of encryption/algorthym e.g. RSA/DSA etc
    RSA : is an encryption algorythm
    -b : the number of bits in the key i.e. how strong encryption is

  3. -C : adds a comment inside public key e.g. note host name and date at the end of following key. Hope it explains…

    ishtiaqmedsmbp2:~ Ishtiaq$ cat .ssh/
    ssh-rsa AAAAB3NsfdsfC1yc2EAAsdfsAADAQABAAAAgQDSiknPUnKI9ISITbKYtapDZ1vo+P1QDGNA37gf8pk8g0AFnVMUZq5TNa0PoLIkNObQbBJUCODEhcRzauwoiEPN5Su+yDgIpbpS1sdfsdf9nmTRR6rnScX2ys8QwCXa4lt/fcOUY+8Mo4j4irzQz+kxddAKLvMoOMe4wD2lPlPblw== Ishtiaq@ishtiaq-ahmeds-macbook-pro-2.local-Sun 20 Apr 2014 12:01:46 EST

Leave a Comment

Array ( [marginTop] => 100 [pageid] => @techish1 [alignment] => left [width] => 292 [height] => 300 [color_scheme] => light [header] => header [footer] => footer [border] => true [scrollbar] => scrollbar [linkcolor] => #2EA2CC )