-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_ssh
executable file
·29 lines (24 loc) · 958 Bytes
/
make_ssh
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
#!/bin/sh
# Set to your unix HOME directory path
home=/home/tom
# Reads variables from previous terraform outputs
jmpbx_ip=$( cat jumpbox_outputs.json | jq -r .jmpbx_ip.value )
devbox_ip=$( cat devbox_outputs.json | jq -r .devbox_ip.value )
username=$( cat setup_outputs.json | jq -r .ssh_user.value )
# Removes any ssh server entries from known hosts if they exist
# If this isn't done the new servers fingerprint may not match
# Leading to an inability to connect
ssh-keygen -f "$home/.ssh/known_hosts" -R "[$jmpbx_ip]:65432"
ssh-keygen -f "$home/.ssh/known_hosts" -R "$devbox_ip"
# Generates a new custom ssh_config file
ssh_config=$( cat <<-_SSH_TEMPLATE_
Host devbox\n
Hostname $devbox_ip\n
User ${username}\n
ProxyCommand ssh ${username}@${jmpbx_ip} -p 65432 -A -W %h:%p\n
Port 22\n
# Example: Forwards port 8080 from the devbox to 65430 on localhost\n
LocalForward 65430 ${devbox_ip}:8080
_SSH_TEMPLATE_
)
echo $ssh_config > ssh_config