Вот окончательный сценарий.
Обновите $ PASSW, затем скопируйте и вставьте его в свой Терминал
# <sshpass> via typinator
# Updated: 2017-01-18_21h36
#
# apt-get update -y; apt-get install expect -qy
# Pass this value to ssh-add
PASSW="myfancypass123"
# Define a name for this script
THIS_SCRIPT="$(date +%Y-%m-%d_%H-%M-%S-%N)".sh
# Create a fresh directory to work from / Clean up
rm -rf ~/temp; mkdir -p ~/temp; cd ~/temp; ls -la
# Output our bash script file - BEGIN
cat <<< '
#!/bin/bash
set -u # Stop if an unbound variable is referenced
set -e # Stop on first error
export HISTIGNORE="expect*";
# Normal CMDs
echo && echo "The process should take about 10 seconds:" && echo
eval "$(ssh-agent -s)"; sleep 0.5;
# Define VAR passed when this bash-script was launched
password="$@"
# Launch the expect magic
expect -c "
spawn ssh-add /root/.ssh/id_rsa
expect "?assword:"
send \"$password\r\"
expect "?password:"
send \"$password\r\"
expect eof"
export HISTIGNORE="";
export password="";
' > $THIS_SCRIPT
# Output our bash script file - END
# Ensure we are in the right path
cd ~/temp; ls -la; sleep 1;
# Run the bash script
chmod +x ./$THIS_SCRIPT; ./$THIS_SCRIPT "$PASSW"; unset password;
# Clean up
rm -rf ~/temp; mkdir -p ~/temp; cd ~/temp; ls -la