# stored passphrase for ssh key

**URL:** <https://forum.ansible.com/t/stored-passphrase-for-ssh-key/30759>\
**Category:** Ansible Project\
**Created:** [July 11, 2019, 3:00pm UTC](https://forum.ansible.com/t/stored-passphrase-for-ssh-key/30759 "2019-07-11T15:00:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen\_Burke](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@Stephen\_Burke](https://forum.ansible.com/u/Stephen_Burke)\
**Post date:** [July 11, 2019, 3:00pm UTC](https://forum.ansible.com/t/stored-passphrase-for-ssh-key/30759/1 "2019-07-11T15:00:52Z")

</div>

Does anyone know a way to store an ssh passphrase during a playbook run? All nodes have the same ssh key/passphrase. I just don’t want to type the same passphrase 100 times during the playbook run. Is there any way to do this with passphrases?

---

<div class="post-metadata">

**Author:** ![Santha\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@Santha\_Kumar](https://forum.ansible.com/u/Santha_Kumar)\
**Post date:** [July 11, 2019, 3:36pm UTC](https://forum.ansible.com/t/stored-passphrase-for-ssh-key/30759/2 "2019-07-11T15:36:04Z")

</div>

Define a variable to fetch it from file.

---

<div class="post-metadata">

**Author:** ![Stephen\_Burke](https://avatars.discourse-cdn.com/v4/letter/s/3be4f8/32.png) [@Stephen\_Burke](https://forum.ansible.com/u/Stephen_Burke)\
**Post date:** [July 11, 2019, 8:16pm UTC](https://forum.ansible.com/t/stored-passphrase-for-ssh-key/30759/3 "2019-07-11T20:16:33Z")

</div>

Figured it out. Add the following to your bash\_profile:

`

# Configure ssh-agent (begin)

SSH\_ENV=“$HOME/.ssh/environment”  
function start\_agent {  
echo “Initializing new 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 ~/.ssh/$(whoami);  
}

# Source SSH settings, if required

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

# Configure ssh-agent (end)

`
