Setting up SSH Agent¶
Ensuring the SSH Daemon is Running¶
Copy and paste the following script into your PowerShell terminal.
. {
# Define the service name
$serviceName = "ssh-agent"
# Check if the service exists
$service = Get-Service -Name $serviceName -ErrorAction SilentlyContinue
if ($service) {
# 1. Check if Startup Type is already Automatic
# We use Get-CimInstance to reliably check StartMode on both PowerShell 5.1 and 7+
$cimService = Get-CimInstance -ClassName Win32_Service -Filter "Name='$serviceName'"
if ($cimService.StartMode -ne "Auto") {
Write-Host "Configuring '$serviceName' startup type to Automatic..."
Get-Service -Name $serviceName | Set-Service -StartupType Automatic
} else {
Write-Host "Startup type for '$serviceName' is already set to Automatic."
}
# 2. Check if the service is already Running
# Refresh the service object to get the latest status
$service.Refresh()
if ($service.Status -ne "Running") {
Write-Host "Starting '$serviceName'..."
Start-Service -Name $serviceName
} else {
Write-Host "Service '$serviceName' is already running."
}
# 3. Return the final status
Get-Service -Name $serviceName
} else {
Write-Warning "Service '$serviceName' was not found. Please ensure the OpenSSH Client feature is installed on Windows."
}
}
Installing and Configuring Git¶
This guide assumes that you already have Git installed. If you do not have Git installed, please refer to the Git Installation Guide to install and configure it before proceeding.
Once Git is installed, run the following script to configure Git to work with your SSH Agent correctly.
git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe
If the git command does not work or is not found at first, close and reopen your PowerShell terminal and try running the command again.
## Installing and Configuring Git
This guide assumes that you already have Git installed. If you do not have Git installed, please refer to the Git Installation Guide to install and configure it before proceeding.
You can verify your installation by running:
git --version
Loading SSH Keys¶
Adding SSH Keys to Agent¶
After setting up the SSH Agent, you will need to load your SSH keys into the agent. You can do this by running the following command in your PowerShell terminal.
ssh-add $env:USERPROFILE\.ssh\id_ed25519
This will load the SSH private key into the agent. You will be prompted for each key's passphrase.
Verifying Agent Configuration¶
Verify that your configuration file has been made.
Run the following command in Terminal to verify that your configuration file has been made.
cat ~/.ssh/config
If the configuration file does not exist, you will see an error message. If the configuration file exists, you will see the contents of the file or a blank output if the file exists but is empty.
Create the configuration file by doing the following:
Run the following command in Terminal to create the configuration file.
touch ~/.ssh/config
You should now see the configuration file in your ~/.ssh directory.
Next, run the following command to set the contents of the file.
Replace Identity File Name
If you are not using the default file name, after running this command you will need to use nano or vim to edit the file and replace ~/.ssh/id_ed25519 with the path to your key file, such as ~/.ssh/id_something or the name you specified when generating the key. This was set when you generated the key and chose the file name. Make sure you choose the correct version of the configuration based on whether you have a passphrase set and plan on using Apple Keychain or not.
cat <<EOF > ~/.ssh/config
Host *
UseKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519
EOF
cat <<EOF > ~/.ssh/config
Host *
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519
EOF
Adding SSH Keys to Agent¶
Now that your configuration file has been set, you can add your SSH keys to the agent.
If you set a passphrase when generating the key, you will need to enter the passphrase to add the key to the agent, otherwise you will not be prompted for a passphrase. If you wish to save the passphrase to the keychain, allowing you to use your passphrase-protected key without having to enter the password every time, run the following command to add the key to the agent with the keychain option.
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
If you did not set a passphrase, or wish to add the key to the agent without the keychain option, run the following command.
ssh-add ~/.ssh/id_ed25519
Verifying Agent Configuration¶
Verify that your configuration file has been made.
Run the following command in Bash to verify that your configuration file has been made.
cat ~/.ssh/config
If the configuration file does not exist, you will see an error message. If the configuration file exists, you will see the contents of the file or a blank output if the file exists but is empty.
Create the configuration file by doing the following:
Run the following command in Bash to create the configuration file.
touch ~/.ssh/config
You should now see the configuration file in your ~/.ssh directory.
Next, run the following command to set the contents of the file.
Replace Identity File Name
If you are not using the default file name, after running this command you will need to use nano or vim to edit the file and replace ~/.ssh/id_ed25519 with the path to your key file, such as ~/.ssh/id_something or the name you specified when generating the key. This was set when you generated the key and chose the file name.
cat <<EOF > ~/.ssh/config
Host *
AddKeysToAgent yes
IdentityFile ~/.ssh/id_ed25519
EOF
Adding SSH Keys to Agent¶
Now that your configuration file has been set, you can add your SSH keys to the agent.
If you set a passphrase when generating the key, you will need to enter the passphrase to add the key to the agent and upon every subsequent usage of the SSH key, otherwise you will not be prompted for a passphrase.
If you are running a GNOME-based Linux environment (Debian, Ubuntu, Fedora, etc.), you can configure your GNOME Keyring to store your passphrase for you, similar to the Apple Keychain, allowing you to use your passphrase-protected key without having to enter the password every time. The scope of configuring and using GNOME Keyring is beyond this guide, so please refer to their documentation at GNOME Keyring for more information after finishing this guide.
Add your SSH key to the agent by running the following command.
ssh-add ~/.ssh/id_ed25519
Once your agent has been set up and your keys have been loaded into your agent, you are ready to use your ssh keys with your chosen git provider