Ubuntu SSH setup for Git
-
Generate key
ssh-keygen -t <key_name> -C "[email protected]"
-
add the key to ssh agent
-
start agent in the background
eval "$(ssh-agent -s)"
-
add the private key
ssh-add ~/.ssh/<key_name>
-
-
make sure the public key is added to github
To automatically start the agent and register the key on login, add the following to ~/.bashrc
# Start SSH agent if not running and add keys
if [ -z "$SSH_AUTH_SOCK" ]; then
eval "$(ssh-agent -s)" > /dev/null 2>&1
fi
# Add your GitHub private key
if ! ssh-add -l | grep -q "github"; then
ssh-add ~/.ssh/your_github_key 2>/dev/null
fi