Hum... you try to load ~/id_rsa. Usually, keys are in the ~/.ssh folder. AFAIR ssh is also very picky with file and folder permissions. If a key is in a directory that ssh thinks not secured enough, it won't use it.
If your key is really in ~, move it (and the corresponding .pub file) into the ~/.ssh folder. Make sure you own the files and the ~/.ssh has 0700 mode, ~/.ssh/id_rsa should have 0600 mode. See chmod(1) if you don't know how to do that.
Also, there's no need to give a filename to ssh-add. As per the man-page:
ssh-addadds private key identities to the authentication agent,ssh-agent(1). When run without arguments, it adds the files~/.ssh/id_rsa,~/.ssh/id_ecdsa,~/.ssh/id_ecdsa_sk,~/.ssh/id_ed25519,~/.ssh/id_ed25519_sk, and~/.ssh/id_dsa. After loading a private key, ...
in short :
- make sure your key files are in
~/.sshfolder, - in your
.bashrcfile just usessh-add.
A quick note: Having questions in .bashrc is not necessarily a good thing. There exist situations (but maybe not in WSL) when .bashrc is loaded in non-interactive situations. If you really want to ask questions, read answers, protect the whole thing with a test on PS1
if test "$PS1"; then
if [ -z "$SSH_AUTH_SOCK" ]; then
#start ssh-agent
eval "$(ssh-agent -s)"
fi
# Ask for ssh-add
read -p "Do you want to add your SSH public key? (y/n) " response
# and so on...
fi
To check if you need the PS1 if statement in your .bashrc file you can check for the following piece of code at the top of the .bashrc fileEDIT NOTE:
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
This will exit theI removed technical text that was not mine, but was added by someone else. Style, grammar, typos etc... corrections are always welcome. That someone adds .bashrc script when ithis/her thoughts to my answer is running in an non-interactive situation.
PS: Comment not always thereappreciated. thank you.