-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-ssh-tunnel.sh
52 lines (40 loc) · 1.6 KB
/
create-ssh-tunnel.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
42
43
44
45
46
47
48
49
50
51
52
#! /bin/bash
source $SCRIPT_DIR/utils.sh
# Check if the vantage6-node user already exists
print_step "Checking if the vantage6-node user already exists"
NEW_USER="vantage6-node"
if id -u "vantage6-node" >/dev/null 2>&1; then
print_warning "The vantage6-node user already exists"
else
print_step "Creating new user: $NEW_USER"
sudo useradd $NEW_USER
# Set password for the new user
PASSWORD=$(openssl rand -base64 16)
echo "$NEW_USER:$PASSWORD" | sudo chpasswd
fi
print_step "Executing some steps as sudo user"
source $SCRIPT_DIR/create-ssh-keys.sh
# Tunnel settings
print_step "Setting tunnel settings"
export TUNNEL_HOSTNAME=$OMOP_HOST
if ! check_command "hostname"; then
print_step "Installing hostname package"
sudo dnf install -y hostname &>> $LOG_DIR/install-hostname.log
fi
export SSH_HOST=$(hostname -I | awk '{print $1}')
export SSH_PORT=22
print_step "SSH_HOST: $SSH_HOST, SSH_PORT: $SSH_PORT"
if [ -f "/etc/ssh/ssh_host_rsa_key.pub" ]; then
export SSH_HOST_FINGERPRINT=$(cat /etc/ssh/ssh_host_rsa_key.pub)
else
print_error "File /etc/ssh/ssh_host_rsa_key.pub does not exist."
print_error "Is openssh-server installed and running?"
fi
export SSH_USERNAME=$NEW_USER
export SSH_KEY=$PRIVATE_KEY_FILE
print_step "SSH_KEY: $SSH_KEY"
export TUNNEL_BIND_IP="0.0.0.0"
export TUNNEL_BIND_PORT=$OMOP_PORT
export TUNNEL_REMOTE_IP="127.0.0.1"
export TUNNEL_REMOTE_PORT=5432
print_step "TUNNEL_REMOTE_PORT: $TUNNEL_REMOTE_PORT"