-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathssh.sh
More file actions
34 lines (29 loc) · 894 Bytes
/
Copy pathssh.sh
File metadata and controls
34 lines (29 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env bash
# --------------------------------------------------------
# ssh.sh
# Inicializador de agente SSH robusto
# --------------------------------------------------------
set -euo pipefail
# Cargar librería UI
source "$(dirname "$0")/lib.sh"
ui_init "Gestión de Agente SSH"
SSH_ENV="$HOME/.ssh/agent-environment"
function start_agent {
ui_step "Inicializando agente SSH..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add
ui_success "Agente inicializado."
}
# Comprobar si el agente está corriendo
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
if ps -ef | grep "${SSH_AGENT_PID}" | grep ssh-agent$ > /dev/null; then
ui_success "Agente SSH ya se encuentra activo (PID: $SSH_AGENT_PID)."
else
start_agent
fi
else
start_agent
fi