Skip to main content
deleted 130 characters in body
Source Link
exore
  • 261
  • 1
  • 6

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-add adds 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 ~/.ssh folder,
  • in your .bashrc file just use ssh-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.

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-add adds 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 ~/.ssh folder,
  • in your .bashrc file just use ssh-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 file:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

This will exit the .bashrc script when it is running in an non-interactive situation.

PS: Comment not always there.

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-add adds 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 ~/.ssh folder,
  • in your .bashrc file just use ssh-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
 

EDIT NOTE:

I removed technical text that was not mine, but was added by someone else. Style, grammar, typos etc... corrections are always welcome. That someone adds his/her thoughts to my answer is not appreciated. thank you.

Minor typos, formatting
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

Also, there's no need to give a filename to ssh-add. As per the doc man-page:

DESCRIPTION
    ssh-add adds 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,
...

ssh-add adds 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, ...

A quick note: Having questions in .bashrc is not necessarily a good thing. There exist situations (but maybe not in wslWSL) when .bashrc is loaded in non interactive situation-interactive situations. If you really want to ask questions, read answers, protect the whole thing with a test on PS1PS1

To check if you need the SP1 ifPS1 if statement in your .bashrc file you can check for the following peacepiece of code at the top of the .bashrc file:

This will exit the bashrc.bashrc script when it is running in an non interactive-interactive situation. 

PS: Comment not always there.

Also, there's no need to give a filename to ssh-add. As per the doc :

DESCRIPTION
    ssh-add adds 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,
...

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 situation. If you really want to ask questions, read answers, protect the whole thing with a test on PS1

To check if you need the SP1 if statement in your .bashrc file you can check for the following peace of code at the top of the .bashrc file:

This will exit the bashrc script when it is running in an non interactive situation. PS: Comment not always there.

Also, there's no need to give a filename to ssh-add. As per the man-page:

ssh-add adds 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, ...

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

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 file:

This will exit the .bashrc script when it is running in an non-interactive situation. 

PS: Comment not always there.

Added a code block with explanation that PS1 check not always required is
Source Link
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
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 SP1 if statement in your .bashrc file you can check for the following peace of code at the top of the .bashrc file:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

This will exit the bashrc script when it is running in an non interactive situation. PS: Comment not always there.

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
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 SP1 if statement in your .bashrc file you can check for the following peace of code at the top of the .bashrc file:

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

This will exit the bashrc script when it is running in an non interactive situation. PS: Comment not always there.

Source Link
exore
  • 261
  • 1
  • 6
Loading