sudo apt install expect
cp rootKey ~/.ssh
chmod 600 ~/.ssh/rootKey
nano ~/.bashrc
eval $(ssh-agent -s) > /dev/null 2>&1
expect ~/ssh.sh > /dev/null 2>&1
nano ~/ssh.sh
#!/usr/bin/expect -f
spawn ssh-add /home/arinc9/.ssh/rootKey
expect "Enter passphrase for /home/arinc9/.ssh/rootKey:"
send "passphrase\\n";
expect "Identity added: /home/arinc9/.ssh/rootKey (root-access-key)"
interact
nano ~/.bash_logout
if [ "$SSH_AGENT_PID" != "" ]; then
eval $(ssh-agent -k)
fi
- Use
exit
to logout otherwise ssh-agent
will keep running on the background