Show pageOld revisionsBacklinksExport to PDFBack to top This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Script: Connect to VPN, and then SSH into remote server ====== <WRAP center round alert 60%>Puting passwords in scripts is insecure! Use ssh keys instead.</WRAP> <WRAP center round important 60%>Assumption: You are using network manager, and have a VPN connection named VPN1 already set up</WRAP> Create a script called **conn** and make it executable <code bash| conn> #!/bin/bash if [ $1 = 'srv1' ]; then nmcli con up id VPN1 sshpass -p 'remotepassword' ssh remoteuser@192.168.2.20 nmcli con down id VPN1 fi </code> Calling the script with **./conn srv1** will up the VPN interface, and connect to remote server via SSH, and down the interface when SSH exists. You can move the script to /usr/bin directory to be able to call it from anywhere, and without using **./** For better (any) security, don't use password in a script, or better yet, use a ssh key pair. Tutorial here [[linux:misc:ssh_key_pairs|Using SSH keys to authenticate users]], and here [[linux:misc:ssh_keys|Setup SSH public/private keys and disabling password login]] <WRAP center round info 60%>Copy the if/fi block for each remote server and/or vpn interface</WRAP> linux/vpn_clients/auto_vpn_and_ssh_sctript.txt Last modified: 2019/10/31 09:05by 127.0.0.1