- Create a folder at the root of your user home folder
(Example:
C:/Users/uname/
) called.ssh
. - Create the following files if they do not already
exist (paths begin from the root of your user home
folder):
.ssh/config
.bash_profile
.bashrc
Follow the steps in the section named "Generating a new SSH Key" found in the following documentation from GitHub: Generating a new SSH key and adding it to the ssh-agent
Add the following text to .ssh/config
(.ssh
should be found
in the root of your user home folder):
Host github.com
Hostname github.com
IdentityFile ~/.ssh/id_ed25519
First, ensure that following lines are added to .bash_profile
,
which should be found in your root user home folder:
test -f ~/.profile && . ~/.profile
test -f ~/.bashrc && . ~/.bashrc
Now, add the following text to .bashrc
, which should be found
in your root user home folder:
# Start SSH Agent
#----------------------------
SSH_ENV="$HOME/.ssh/environment"
function run_ssh_env {
. "${SSH_ENV}" > /dev/null
}
function start_ssh_agent {
echo "Initializing new SSH agent..."
ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo "succeeded"
chmod 600 "${SSH_ENV}"
run_ssh_env;
ssh-add ~/.ssh/id_ed25519;
}
if [ -f "${SSH_ENV}" ]; then
run_ssh_env;
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_ssh_agent;
}
else
start_ssh_agent;
fi
The part that launches the ssh agent is valuable. However, I'm not persuaded there is a benefit in the git config file. The Default key name is "id_rsa" and that is what ssh will look for. I think the config file is not having an effect. At least for me...
In my case, the name of the key is different for every server and, for reasons I cannot understand, the ssh system only wants to look for "id_rsa". On Linux, this is a symptom of a permissions problem, permissions should be 700. But in Windows, it appears not possible to set permissions at all. In the Git bash shell, permissions always have g+r and o+r.
The config file is ignores, at least for me. You can see same result if you name your key in another file, put in
IdentityFile ~/.ssh/new_keyname
And it wont work. If it does work, I'd love to hear from you.