LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Keeping VPN Open Through Terminal (https://www.linuxquestions.org/questions/linux-networking-3/keeping-vpn-open-through-terminal-4175470974/)

NotAComputerGuy 07-26-2013 02:51 AM

Keeping VPN Open Through Terminal
 
When I SSH into my a remote computer to use a VPN, I use the command line with OpenVPN. The question I have is I cannot use & at the end so it keeps running when I exit SSH, due to needing to enter my usename and password, so how do I keep the network connected and log out of SSH?

Thanks

Firerat 07-26-2013 03:18 AM

One way is to use screen
You can then disconnect ssh but the VPN should still be running
re-attach to screen with screen -x ( if only one session, see its manual for full list of flags )

But
I'm assuming you are logging in via ssh to start the VPN server

The username/password is for what?
is it to get root?

You should probably start OpenVPN as a service
I'd be surprised if OpenVPN didn't have a preconfigured script for this.
so something like
Code:

sudo service OpenVPN start
would do it, ( or sudo /etc/init.d/OpenVPN )

NotAComputerGuy 07-26-2013 01:15 PM

Thanks for the response. I will look into screen. I am running OpenVPN as a user, it's just after I do the VPN command, it asks me for my VPNs username and password. That is why I can't use & at the end.

Firerat 07-26-2013 01:53 PM

Quote:

Originally Posted by NotAComputerGuy (Post 4997399)
Thanks for the response. I will look into screen. I am running OpenVPN as a user, it's just after I do the VPN command, it asks me for my VPNs username and password. That is why I can't use & at the end.

Ahh, right ok

Well, the 'super fast' tutorial for screen in your use case
  1. ssh to your box
  2. screen
    Will diplay some help and stuff
  3. issue your VPN commnads, etc
  4. Ctrl+a , then Ctrl+d
    That detaches the screen, whatever was running is still running
  5. you are now free to exit ssh
  6. to reattach your screen session, screen -x


You can have more than one screen session, think of it as multiple windows/tabs.
The really handy thing with screen is the session still runs even if your ssh drops
for instance, ConnectBot on Android and you loose signal.

NotAComputerGuy 07-27-2013 05:43 AM

Perfect!

Thank you very much!

zhjim 07-30-2013 03:09 AM

Just another way. Probably very old school but still very nice.

Start your vpn connection but put a nohup in front of it. This makes the command immune to hangups. So when you log out the process keeps on running. Also put the & at the end to send the process into background. I know you say how do I input my user name and such. When you send the process into background with & the shell gives you a number in square brackets. This is a job number and with fg <job number> you can get the process to be shown in foreground. Now enter your credentials, suspend the job with <CTRL>+Z and have it run in the background with bg <job number>.

If you are not afraid of work check the output of jobs.


All times are GMT -5. The time now is 02:32 AM.