I'm using a script that executes
eval `ssh-agent`
ssh-add
which prompts you to input your SSH passphrase. Is it possible to input the passphrase from the script? The goal of this is to open connection to git repo whenever I open GitBash without having to constantly input my passphrase. I know putting passphrase in a script is terrible security, but I really don't care. I'm doing for testing.
$ ssh-keygen -p -f ~/.ssh/id_ed25519 > Enter old passphrase: [Type old passphrase] > Key has comment '[email protected]' > Enter new passphrase (empty for no passphrase): [Type new passphrase] > Enter same passphrase again: [Repeat the new passphrase] > Your identification has been saved with the new passphrase.
Using passphrases increases the security when you are using SSH keys. Using a key without a passphrase can be risky. If someone obtains a key (from a backup tape, or a one-time vulnerability) that doesn't include a passphrase, the remote account can be compromised.
Starting ssh-agentOn most Linux systems, ssh-agent is automatically configured and run at login, and no additional actions are required to use it. However, an SSH key must still be created for the user. The ssh-agent command outputs commands to set certain environment variables in the shell.
SSH uses private/public key pairs to protect your communication with the server. SSH passphrases protect your private key from being used by someone who doesn't know the passphrase. Without a passphrase, anyone who gains access to your computer has the potential to copy your private key.
Answer how to do it is here:
https://ifireball.wordpress.com/2015/01/12/automatic-loading-of-ssh-keys-from-scripts/
Summary:
echo "exec cat" > ap-cat.sh
chmod a+x ap-cat.sh
export DISPLAY=1
echo $MY_SSH_PASS | SSH_ASKPASS=./ap-cat.sh ssh-add ~/.ssh/id_rsa
rm ap-cat.sh
Note: you need to export the DISPLAY
environment variable to some value.
If you're going to do that you'd be better off just not using a passphrase on the key. In which case you wouldn't even need to use ssh-agent
. You can change or remove a passphrase from an existing key with ssh-keygen -p
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With