如何在 Debian 6 上设置和配置 OpenVPN 服务器

Getting Started

You will need to open an SSH connection on your cloud server as the root user or an SSH connection to a user with sudo access. This guide assumes a user with sudo access. However you can set things up using root just by stripping the 'sudo' from the start of each command. If your system is running on Linux or Mac, you can use SSH with the Terminal program. If you are using Windows, you can use SSH with PuTTY. Once you have the Terminal opened, assuming you're using a Linux/Mac system, you can login by typing the following command:
ssh username@ipaddress

当你被要求时,输入密码,你已经准备好开始设置OpenVPN。

Install OpenVPN and generate necessary files


在我们开始安装 OpenVPN 及其先决条件之前,我们应该确保我们系统上的所有包都更新。

sudo apt-get update

这应该有 apt,Debian 的包管理器. 下载所有具有它们的软件包的更新。

sudo apt-get upgrade

在我们的系统下载了所有更新后,我们终于可以安装OpenVPN。

sudo apt-get install openvpn udev

一旦安装完成,您就可以开始配置OpenVPN。 首先,您应该将所有文件从默认目录复制到目录中,以便云服务器读取它们。

sudo cp -r /usr/share/doc/openvpn/examples/easy-rsa /etc/openvpn

现在你已经完成了,你可以开始为你的VPN生成RSA算法文件。当你生成这些密钥时,你将被要求提供各种值。

首先,进入以下目录:

cd /etc/openvpn/easy-rsa/2.0/

然后生成 RSA 文件:

source ./vars
sudo ./clean-all
sudo ./build-ca

证书生成后,您可以为服务器创建私钥。 要做到这一点,请输入以下命令,并将服务器更改为您希望OpenVPN服务器的名称。

sudo . /etc/openvpn/easy-rsa/2.0/build-key-server server

生成 Diffie Hellman 关键交换参数。

sudo . /etc/openvpn/easy-rsa/2.0/build-dh

现在,为每个客户端生成此安装的 OpenVPN 将托管的密钥,您应该为每个客户端此安装将托管此步骤,确保每个客户端的密钥标识符是独一无二的。

sudo . /etc/openvpn/easy-rsa/2.0/build-key client

现在将服务器证书和密钥的文件移动到 /etc/openvpn 目录. 用您使用的文件名更换 server.crt 和 server.key。

sudo cp /etc/openvpn/easy-rsa/2.0/keys/ca.crt /etc/openvpn
sudo cp /etc/openvpn/easy-rsa/2.0/keys/ca.key /etc/openvpn
sudo cp /etc/openvpn/easy-rsa/2.0/keys/dh1024.pem /etc/openvpn
sudo cp /etc/openvpn/easy-rsa/2.0/keys/server.crt /etc/openvpn
sudo cp /etc/openvpn/easy-rsa/2.0/keys/server.key /etc/openvpn

如果您需要删除某人的VPN访问权限,只需发送以下两个命令,以删除客户端的名称代替客户端

sudo . /etc/openvpn/easy-rsa/2.0/vars
sudo . /etc/openvpn/easy-rsa/2.0/revoke-full client1

Configure OpenVPN


现在你已经生成了我们配置的文件,你可以继续配置你的OpenVPN服务器和客户端。

sudo gunzip -d /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf /etc/openvpn
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf ~/
cd

您应该修改客户端配置文件以匹配您想要的内容。您还可以更改下列文件中的几个值以匹配您想要的内容。 为了做到这一点,您首先要更改远程选项,以便它可以连接到您的云服务器的IP地址,无论您在哪个端口上配置了您的OpenVPN运行。 然后更改certkey值以反映您自己的证书和密钥的名称。 经过编辑后,您可以通过键入Ctrl+X,键入y,然后点击 Enter。

现在将客户端配置文件,以及位于 /etc/openvpn/easy-rsa/2.0/keys 的客户端密钥和证书复制到客户端的本地机器。

nano ~/client.conf

完成此操作后,您只需要对服务器配置文件进行一些更改,然后更改确认关键选项指向的文件,以匹配您的服务器正在使用的证书和密钥。

sudo nano /etc/openvpn/server.conf

完成后,你已经准备好了!只需重新启动OpenVPN,你就可以在Debian 6上安装OpenVPN了!

sudo /etc/init.d/openvpn restart
Published At
Categories with 技术
Tagged with
comments powered by Disqus