Setting Up Public Key Authentication on Client Server
Setting up public key authentication to access a particular remote host is a
one-time procedure comprising of three steps.
Step 1: Generate a public/private key pair on your
webserver.
Use the
ssh-keygen
command to generate public/private
key pair. The key-type flag -t is mandatory, accepting either "rsa" or "dsa" as an
argument. In the example given, the -f option is also used to override the default name
and location for the resulting private-key file.
When prompted for a passphrase, you can enter appropriate phrase or
keep it empty.
$ ssh-keygen -t dsa -f ./<KEY_NAME>
The command produces two text files in current folder: The
<KEY_NAME>
folder contains the private key, and
<KEY_NAME>
.pub folder contains the public key. The private key
must be kept secret. Accordingly, access to private key is restricted to the file owner
and its contents are encrypted using the passphrase.
You can recreate
<KEY_NAME>
.pub from
<KEY_NAME>
by executing the following command: $
ssh-keygen -y -f ./<KEY_NAME> > <KEY_NAME>.pub
Step 2: Install the public key on the remote host to which you want to
connect.