Windows SSH-related

Completed Low
Start
July 12, 2020
End
July 12, 2020
Period
1Days
PIC
Last Updated
July 12, 2020
Tags
windows

SSH on Windows Environment

Win10: ssh-add returns “Error connecting to agent: No such file or directory”

This is likely because the ssh-agent service is disabled. Open PowerShell as Administrator and execute the following:

Set-Service -Name ssh-agent -StartupType Manual
Start-Service ssh-agent

Generate SSH Public and Private Keys

Command to Generate SSH Key

cd "Your user folder"\.ssh
ssh-keygen -t rsa -C address@example.com

Generating public/private rsa key pair.
Enter file in which to save the key (/home/.ssh/id_rsa):    ← Just press [Enter] without typing anything
Enter passphrase (empty for no passphrase):    ← Enter a passphrase of your choice
Enter same passphrase again:        ← Re-enter for confirmation
Your identification has been saved in /home/.ssh/id_rsa.
Your public key has been saved in /home/.ssh/id_rsa.pub.
The key fingerprint is:
e8:ae:60:8f:38:c2:98:1d:6d:84:60:8c:9e:dd:47:81 foo@hoge.com

Once generated, you will see two files:

id_rsa: Private key — keep this secret and do not share it
id_rsa.pub: Public key — share this with Bitbucket/GitHub/GitLab

Configure SSH Key on the Client Side

.ssh/config Add the following entry to the .ssh/config file:

Host gitlab.example.com
  User git
  Port <your-specified-port>
  HostName gitlab.example.com
  TCPKeepAlive yes
  identitiesonly yes
  identityFile ~/.ssh/id_rsa → Path to your private key (id_rsa)

Avoid Entering Passphrase Every Time with Git over SSH

Example of the current behavior:

git pull
Enter passphrase for key '/Users/user_name/.ssh/id_rsa':

Solution:

# Register your SSH key with the ssh-agent
ssh-add /Users/user_name/.ssh/id_rsa

# Alternatively, if the key is at ~/.ssh/id_rsa, you can use:
ssh-add -K

# Confirm that the key is registered
ssh-add -l