ssh-add command does not add my identity to ssh-agent

From man ssh-add:

ssh-add adds private key identities to the authentication agent, ssh-agent(1). When run without arguments, it adds the files ~/.ssh/id_rsa, ~/.ssh/id_dsa, ~/.ssh/id_ecdsa and ~/.ssh/identity.[...]

Identity files should not be readable by anyone but the user. Note that ssh-add ignores identity files if they are accessible by others.

So, because of The agent has no identities. error, you probably don't have those files or maybe those files are accessible by others. You can check these using the following command:

ls -l ~/.ssh

Also, after you run ssh-add command, run echo $? to see the error status of the previous command. If exit status returned 0, the command was executed successfully. If exit status returned a non-zero value, the command failed to execute.

See man ssh-add for more info.


Additional to the above considerations, I found that if you're using an alternate shell, you may need to configure it to load ssh-agent. For example, in Zsh, one must add ssh-agent to plugins in .zshrc.

This method works great on Ubuntu 17.10 with the latest Zsh

Others found that with id_ed25519 keys, rsa was working without a plugin. After adding ssh-agent to ~/.zshrc, restart the shell with exec "$SHELL" and execute: ssh-add ~/.ssh/id_ed25519

Enter passphrase for ~/.ssh/id_ed25519: 
Identity added: ~/.ssh/id_ed25519 (user@host)

Tags:

Ssh

Ssh Agent