Setting up SSH Public/Private Keys

Posted by Benjamin Close on November 7, 2008 under Computers, OpenSource | Be the First to Comment

Using SSH for Automatic Key authentication

SSH provides an encrypted tunnel for use with interactive and non interactive terminal sessions. It provides authentication via a number of methods including password, public/private key pairs and challenge keys.

SSH also provides authentication forwarding between machines. This feature allows a user to be able to log on to a machine without the need of typing a password. This is an extreemly strong feature as it means you can provide access to an account or even to execute a command without the need to provide someone with a password.

In order to setup public/private key authentication forwarding both the client and the server must have knowledge of the relevant keys. You must also consider the version of SSH software that the server/client is running as different versions use different files. Generating SSH Keys

The first step is to generate an SSH private/public key pair. For this I assume you are using some version of OpenSSH. There is currently three types of ssh key pairs that can be generated. They are rsa1, rsa and dsa. Of these dsa is the most secure and is the one used by ssh2. To generate the key perform the following:

  ssh-keygen -t rsa1
  ssh-keygen -t rsa
  ssh-keygen -t dsa

The public/private keys will be installed in the following places

SSH VersionKey TypeOpenSSHSSH 2(Commercial)
old ssh1rsa1~/.ssh/identity & ~/.ssh/identity.pubNot Generatable
ssh1rsa2~/.ssh/id_rsa & ~/.ssh/[keywidth]_a & /.ssh2/id_rsa_[keywidth]
ssh2dsa~/.ssh/id_dsa & ~/.ssh/[keywidth]_a &/.ssh2/id_dsa_[keywidth]

Automated Authentication

With the keys generated it is now possible to setup automatic key authentication. This means when you log in to a machine you don’t need to enter your password. The authentication happens by the server encrypting some data with your public key then challenging the client to decript it. For this to happen, the client must have the private key matching the public key.

The procedure to set this up varies up which server you attempting to access. The procedure is basically as follows:

  scp [publickey] user@host:~
  ssh user@host
  cat [publickey] >> [filename]

The above is the basic procedure. However the publickey and filename vary depending on the server/client you are using. A valid example for OpenSSH using dsa keys is:


  scp ~/.ssh/ user@host:~
  ssh user@host
  cat >> ~/.ssh/authorized_keys2

The table below shows which file to copy where:

Local OpenSSH KeyOpenSSH (Remote Machine)SSH2(Commercial) (Remote Machine)
identity.pubUnknown At presentUnknown at present ~/.ssh2/ & “echo key >> authorization” ~/.ssh2/ & “echo key >> authorization”

Note 1: In order to generate an SECSH compliant key the following OpenSSH Command can be used:

  ssh-keygen -e -f [KEY].pub > [KEY]

Donations keep this site alive

Add A Comment