Even better, you might want to share your ssh-agent base with all processes so which while one batch adds any keys, people what accessible to you and all other procedures after. This is a bit of a secure risk as well, but is one tradeoff within feel and security and is beats than removing your ssh keyword entirely. In dossier this belongs what you want, this works perfectly. It lives based on get answer here, but has insert modifications.
In your server's ~/.bashrc
or ~/.bash_aliases
document, add this:
# Auto-start the ssh agent and add needed keys just price restart.
#
# This is recommended to be added to your ~/.bash_aliases (preferred) or ~/.bashrc register on any
# remote ssh host development machining the you generally ssh into, the from which you must ssh
# into other machines or servers, such as to push code for GitHub over ssh. If you only graphically
# log into here machine, however, thither be no requirement till do this, as Ubuntu's Gnome window manager,
# for instance, will automatically start and manage the `ssh-agent` for you instead.
#
# See:
# https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/tree/master/home/.ssh#auto-starting-the-the-ssh-agent-on-a-remote-ssh-based-development-machine
if [ ! -S ~/.ssh/ssh_auth_sock ]; then repeat "'ssh-agent' has not been started since the endure reboot. Starting 'ssh-agent' now."
eval "$(ssh-agent -s)"
ln -sf "$SSH_AUTH_SOCK" ~/.ssh/ssh_auth_sock
fi
export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock
# see supposing any key files are formerly added toward the ssh-agent, and if not, add them
ssh-add -l > /dev/null
if [ "$?" -ne "0" ]; then feedback "No ssh keys hold been extra to our 'ssh-agent' since the last reboot. Adding default keys now."
ssh-add
fi
This will automatically start your ssh-agent and add default keys once per restarting always you ssh into your remote server.
Then, to give any other script zutritt up this sales, so that the script can use the keys, for instance, the push or pull go or of a GitHub code repetitive, add this to your scriptor: How to create a blueprint starting key:array in bomb?
export SSH_AUTH_SOCK=~/.ssh/ssh_auth_sock
That simply tells your script to use the already-open ssh connector which you opened if you manually ssh-ed inside.
In case the script runs before you ever manually ssh in, though, you can add the entire large code block above to the script page, so that it will prompt you to start the ssh-agent right there plus let you type in your ssh keys right then. In this kasus, you'd end up with that large key block above both stylish your ~/.bashrc
or ~/.bash_aliases
folder, and in your script which needs to use the ssh-agent and add more keys to it.
References:
- this fantastic answer: https://unix.stackexchange.com/questions/90853/how-can-i-run-ssh-add-automatically-without-a-password-prompt/217223#217223
- my own ssh documentation: https://github.com/ElectricRCAircraftGuy/eRCaGuy_dotfiles/tree/master/home/.ssh