Solved Automatically add my SSH keys for remote connection upon startup

I'm running FreeBSD 13.1 as a VM that I use to learn and work on project.
I would like to automatically add my ssh key to the ssh-agent.

I've create the following bash script to run on demand:

#!/usr/bin/env bash
# File: addMyKeys.sh

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/GitHub

I then chmod +x to my file and can execute it.

$ addMyKeys.sh
Agent pid 1071
Enter passphrase for /home/bob/.ssh/GitHub:
After typing my passphrase it looks like it is all good

Identity added: /home/bob/.ssh/GitHub (myname@mydomain.com)
However I'm still unable to establish my ssh connection

$ ssh -T git@github.com
git@github.com: Permission denied (publickey).

Typing these exact same commands on my bash prompt does the same output but seems to add the key successfully and allow the ssh

$ eval "$(ssh-agent -s)"
Agent pid 1071
$ ssh-add ~/.ssh/GitHub
Enter passphrase for /home/bob/.ssh/GitHub:
Identity added: /home/bob/.ssh/GitHub (myname@mydomain.com)
$
$ ssh -T git@github.com
Hi bob! You've successfully authenticated, but GitHub does not provide shell access.
Anyone would nice enough to help my understand what I am missing?

Thanks in advance!
 
Back
Top