0

I have an Ubuntu 14.04 Server with an OpenVPN Server running on it.

I would like to have an OpenVPN client from this machine connect to a remote machine in order to save backup files on the remote machine.

I already read that it is possible to have server and client and I have config and certificate files for the client in a folder seperate from the normal openvpn folder.

The big problem is that the Backup-User has no root priviledges and is not supposed to receive any either. As a result this user cannot create a VPN connection.

The OpenVPN client connection should only be active when needed, so I can't just activate it and leave it be. Is there maybe a way to start the VPN client connection automatically at a certain time and same with closing the connection?

2 Answers2

1

One way to solve your problem might be to use a cronjob. Run crontab with the command crontab -eand insert your command and the desired timing. To run a job at a certain time as root, just run sudo crontab -e when creating the rule. Rules follow the following scheme:

minute hour day month weekdays yourbashcommandhere

For example, if you wanted to run the job every wednesday at 10am, your rule should look like this:

* 10 * * 3 yourbashcommand

More info on timing options can be found here: http://www.adminschoice.com/crontab-quick-reference

Gasp0de
  • 464
  • but also the path to script or program must be added to sudoers, as user does not have privileges to run it with sudo without password required... – Ivan Temchenko Mar 08 '16 at 08:11
  • @IvanTemchenko Is that the case, even when you create the rule with "sudo crontab -e"? I think this is only necessary if you run crontab without sudo and then put in a command like "sudo apt-get update", but the way i used in the answer should insert it into the root users crontab? – Gasp0de Mar 08 '16 at 08:21
  • heh, in that case you dont need sudo before your command as it will be runed as root anyway... http://askubuntu.com/questions/173924/how-to-run-a-cron-job-using-the-sudo-command – Ivan Temchenko Mar 08 '16 at 08:47
  • oh, thats other answer suggesting to use sudo in command. soz ) – Ivan Temchenko Mar 08 '16 at 08:47
-1

You can either run crontab scedule a certain command Sudo crontab -e Then edit it like this

Minutes hour day month weekday

To connect to openvpn server at every mondat 9 am

* 9 * * 1   openvpn --config server.ovpn

Or use at its easier but it works once untill you set it again

Sudo apt-get install at
at 09:00
"Your commands press enter for multiple commands and ctrl+d to apply the job"

atq 
"To see sceduled jobs"

atrm "jobnumber to delete the job"