Using SSH keys
Last modified: 03 October 2024When you clone your project from a Git repository with SSH keys instead of a credential helper, you need to ensure that your local SSH agent is running.
If the SSH agent is running, you can add your local SSH keys to the agent using the ssh-add
command.
Check the following example:
However, you may receive an error on Linux and Windows since the SSH agent is not running by default on these systems.
To resolve such issues, use the following steps:
Ensure that you are running your local PowerShell as an administrator.
Enter the following command:
Set-Service ssh-agent -StartupType Automatic
Start-Service ssh-agent
Get-Service ssh-agent
Start the SSH agent with the following command:
Add the following lines to ~/.bash_profile
or ~/.zprofile
if you prefer to use the Zsh
shell instead of bash
.
if [ -z "$SSH_AUTH_SOCK" ]; then
RUNNING_AGENT="`ps -ax | grep 'ssh-agent -s' | grep -v grep | wc -l | tr -d '[:space:]'`"
if [ "$RUNNING_AGENT" = "0" ]; then
ssh-agent -s > $HOME/.ssh/ssh-agent
fi
eval `cat $HOME/.ssh/ssh-agent` > /dev/null
ssh-add $HOME/.ssh/<your ssh key> 2> /dev/null
fi
On the last line of the suggested code, replace <your ssh key> with your specific ssh key. For example, ssh-add $HOME/.ssh/id_ed344 2> /dev/null