-
Notifications
You must be signed in to change notification settings - Fork 0
SSH
Greg Flynn edited this page Mar 30, 2020
·
5 revisions
ssh-keygen -t rsa -b 4096 -C "gregf36665@gmail.com"This script should be added to a .bashrc or .bash_profile to automatically add ssh keys to the ssh agent. This means that any passwords only need to be typed in on the first launch of a bash session.
env=~/.ssh/agent.env
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; }
agent_start () {
(umask 077; ssh-agent >| "$env")
. "$env" >| /dev/null ; }
agent_load_env
# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?)
if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then
agent_start
ssh-add ~/.ssh/$keyName
elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then
ssh-add ~/.ssh/$keyName
else
echo "At least 1 key already added"
echo `ssh-add -l`
fiThe config file allows for unique settings to be specified for specific hosts. Note many more features can be specified. The most common ones to use would be the key and username
Host hostname
IdentityFile ~/.ssh/id_rsa
Port 22
User username