-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggle-ssh-jumpserver.sh
executable file
·42 lines (33 loc) · 1.02 KB
/
toggle-ssh-jumpserver.sh
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
35
36
37
38
39
40
41
#!/usr/bin/env bash
USAGE="toggle-ssh-jumpserver.sh command user jump-server-name
command
'enable' if the jump server should be enabled, else 'disable'
user
The user whose ssh config should be edited
jump-server
The name of the jump server to use. Needs to correspond to an entry in the user's ssh config"
. "$(dirname $BASH_SOURCE)/lib/parse_args.sh"
REQUIRED=("command" "user" "jump-server")
parse_args __USAGE "$USAGE" "$@"
set_trap 1 2
USER="${NAMED_ARGS['user']}"
JS="${NAMED_ARGS['jump-server']}"
STATE="${NAMED_ARGS['command']}"
LOGFILE="/var/log/jumpserver_toggle.log"
USER_HOME="$(getent passwd "$USER" | cut -d: -f6)"
{
if [[ ! -f "$USER_HOME/.ssh/config" ]]
then
echo "No ssh config found for user $USER!"
exit 1
fi
if [[ "$STATE" == "enable" ]]
then
echo -n 'Enable '
sed -i "s/#ProxyJump ${JS}/ProxyJump ${JS}/g" $USER_HOME/.ssh/config
else
echo -n 'Disable '
sed -i "s/ ProxyJump ${JS}/ #ProxyJump ${JS}/g" $USER_HOME/.ssh/config
fi
echo "jump server $JS for user $USER"
} | tee -a "$LOGFILE"