ssh-add adds private key identities to the authentication agent ssh-agent. For example ,while using git under linux , we can add ssh private key into github so that we can enable SSO .

ssh-add depends on ssh-agent which means ssh-agent service needs to be running while running ssh-add , if below error been showed then it means somehow you don’t have ssh-agent running .

$ ssh-add .ssh/id_ed25519
Error connecting to agent: Connection refused

Solution:

For bash/zsh

$ eval "$(ssh-agent -s)"

For tcsh

$ eval `ssh-agent -c`

Now you should be able to add your SSH private key to the ssh-agent successfully.