Skip to content

Commit 478b5fd

Browse files
ssh: fixed ssh-agent creation
1 parent 20d3f92 commit 478b5fd

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

  • .oh-my-shell/shellrc/plugins/ssh

.oh-my-shell/shellrc/plugins/ssh/post.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ cat <<EOF >$SSH_AGENT_SETUP_SCRIPT
1414
1515
# Try to load current ssh-agent
1616
if test -f \$USER_SSH_AGENT_ENV; then
17-
source \$USER_SSH_AGENT_ENV
17+
source \$USER_SSH_AGENT_ENV
1818
else
19-
SSH_AGENT_PID='missing'
19+
SSH_AGENT_PID='missing'
2020
fi
2121
22+
# Find ssh-agent process
2223
agentPids="\$(pgrep -u $USER 'ssh-agent')"
2324
if echo "\$agentPids" | grep -q "\$SSH_AGENT_PID"; then
2425
# Configured agent is also a running agent
@@ -27,6 +28,9 @@ cat <<EOF >$SSH_AGENT_SETUP_SCRIPT
2728
2829
# Configured agent is gone. Recreating a new agent"
2930
# Start new ssh-agent
31+
# SSH_USE_STRONG_RNG might block on computer lacking enough entropy
32+
# (such as device without a hardware random generator)
33+
export SSH_USE_STRONG_RNG=1
3034
eval \$(ssh-agent) >/dev/null
3135
3236
# Remove eventual previous ssh-agent environment configuration
@@ -41,11 +45,14 @@ EOF
4145
# Create a single ssh-agent instance across all terminal sessions, for each predefined agent
4246
# src: https://stackoverflow.com/a/32592488/219728
4347

44-
USER_SSH_AGENT_DIR="$HOME/.ssh/.agent"
48+
USER_SSH_AGENT_DIR="$HOME/.ssh/agent"
4549
USER_SSH_AGENT_ENV_0="$USER_SSH_AGENT_DIR/env_default"
4650
USER_SSH_AGENT_ENV_1="$USER_SSH_AGENT_DIR/env_unsecure"
4751

4852
for f in "$USER_SSH_AGENT_ENV_0" "$USER_SSH_AGENT_ENV_1"; do
53+
# Create missing folders
54+
mkdir -p "$(dirname $f)"
55+
4956
# Run ssh agent setup script
5057
flock --exclusive --unlock \
5158
"${f}.lock" \
@@ -62,3 +69,5 @@ for f in "$USER_SSH_AGENT_ENV_0" "$USER_SSH_AGENT_ENV_1"; do
6269
. "$f"
6370
fi
6471
done
72+
73+
rm -f "$SSH_AGENT_SETUP_SCRIPT"

0 commit comments

Comments
 (0)