How to Add Ssh Keys with ssh-add In Linux? – POFTUT

How to Add Ssh Keys with ssh-add In Linux?


SSH protocol provides different ways for authentication. Key based authentication is the most secure one. In order to use key based authentication we should store the key in a command place. SSH agents reads keys and uses for authentication with remote system. We can use ssh-add to store keys in a common path.

Key Files

Public and private keys are store in files according to their algorithm.

  • ~/.ssh/identity  holds RSA version 1 identity
  • ~/.ssh/id_dsa  holds DSA version 2 identity
  • ~/.ssh/id_rsa holds RSA version 2 identity

If identity keys are readable by others they can not used by ssh-add.

Start Ssh Agent

ssh-agent  is used to read keys for authentication. ssh-agent  works as daemon. We can simply start it like below.

$ eval `ssh-agent`
Start Ssh Agent
Start Ssh Agent

Add Ssh Key

We will add ssh keys with the ssh-add . We will provide the key we want to add. If the key is protected with encryption we need to provide the password. In this example we will add key named mykey . This key is located in the current working directory but we can also provide absolute path of the key.

$ ssh-add mykey
Add Ssh Key
Add Ssh Key

List Ssh Keys

We can list added ssh keys with the -L  option like below. This will also print the type of the key with the name at the end of the line.

$ ssh-add -L
List Ssh Keys
List Ssh Keys

LEARN MORE  How To Create and Setup SSH Keys For Passwordless and Public Key Based Authentication In Linux?

Leave a Comment