3

I am using SoftEther VPN client to connect to a remote machine. In order to ssh into the remote machine, I first have to take the following steps:

cd ~/vpnclient
sudo ./vpnclient start
./vpncmd
2 (asked to pick an option)
Enter "" (with no input)
accountconnect
<my_name_1>
exit
sudo dhclient <my_name_2>

After that, I am able to ssh. But I have to do that each time I restart.

I'm sure there must be a way that I can automate all this but I'm not sure where to start. Could I write a shell script to do this, even though it runs a program and then types things within the program? Or should I be doing this with Python?

Any help would be great.

user1551817
  • 175
  • 2
  • 9
  • 29
  • 1
    I automated this in Windows using `vpncmd /client localhost /IN:"C:\folder\ConnectVPN.vpn"` with a batch script and running a loop every so often to check and confirm the VPN interface name is not in "disconnected" status but if if it to run that command, wait, then check that the VPN interface is not "disconnected" again or whatever. I have two line in the VPN file I point the VPN file to but that connection is SSH key auth only but you can specify commands in the file you point to with the `/IN` parameter. Let me know if you're interested in more detail though. – Vomit IT - Chunky Mess Style Jan 12 '19 at 01:32

3 Answers3

5

If you are running Linux as root, you should be able to add a command like

cd /home/username/vpnclient
./vpnclient start

to /etc/rc.local (before the "exit 1" statement if it exists). Theoretically you should only need to run vpncmd once to set up your account, and it should then save that config in vpn_client config.

That said, if you do need to enter this vpncmd, you can do it with bash, for example by adding the following lines to a bash script (or to rc.local) -

(
echo "2"
echo ""
echo "accountconnect"
echo <my_name_1>
echo "exit" ) | ./vpncmd

dhclient <my_name_2>

(Sudo is not needed because you are root).

davidgo
  • 68,623
  • 13
  • 106
  • 163
  • 1
    If you need to wait between sending your input commands, you can also take this same autostart route (rc.local) but use an [Expect](https://linux.die.net/man/1/expect) script instead. – ThatOneDude Jan 15 '19 at 01:12
  • 1
    Or "sleep" if it does not need to be interactive). "sleep" is simpler but "expect" is faster. – davidgo Jan 15 '19 at 01:13
0

Command: ./vpncmd vpnclient> AccountStartupSet

It will connect your account even after rebooting the system. And you can automate your dhclient by using /etc/network/interfaces file

0

Google give me this form when I face the same request. Then I find out a best way: #vpncmd 2 (asked to pick an option) Enter "" (with no input) AccountStartupSet <you_name> exit

Next time just run : vpnclient start