Created
September 7, 2014 15:54
-
-
Save tstellanova/76ee01c1599d9a9433cf to your computer and use it in GitHub Desktop.
Start ssh-agent at startup on ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# typically you'd add this at the end of eg .bashrc | |
# setup ssh-agent | |
SSH_ENV=$HOME/.ssh/environment | |
# start the ssh-agent | |
function start_agent { | |
echo "Initializing new SSH agent..." | |
# spawn ssh-agent | |
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" | |
echo succeeded | |
chmod 600 "${SSH_ENV}" | |
. "${SSH_ENV}" > /dev/null | |
/usr/bin/ssh-add | |
} | |
if [ -f "${SSH_ENV}" ]; then | |
. "${SSH_ENV}" > /dev/null | |
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { | |
start_agent; | |
} | |
else | |
start_agent; | |
fi |
This one works for me on Win 10 machine.
Inside of .bashrc insert this code
#!/bin/bash
eval `ssh-agent -s`
# Add SSH key
ssh-add ~/.ssh/id_rsa
That will start a new agent for every single shell.
It will also never clean it up.
setup ssh-agent
SSH_ENV=$HOME/.ssh/environment
Do I need to have a ~/.ssh/environment file for this to work? I am on a cloud-based IDE called "Cloud 9" using ubuntu 20.04 (ide.cs50.io) and it doesn't have this file, but it does have /etc/environment if that helps.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use this in your .bashrc instead:
Ensure that you have keychain installed