找回密码
 立即注册
搜索
查看: 171|回复: 0

一键部署超级简单易用的openvpn服务器,支持多证书+多账号...

[复制链接]

985

主题

92

回帖

5万

积分

管理员

积分
53561
发表于 2022-6-22 10:34:02 | 显示全部楼层 |阅读模式
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install
9 b; B8 Q1 O. e8 F9 Y1.1. 下载安装
9 M# u3 r( @* [8 m0 I5 [8 H  J; ^4 ?
  1. # git clone https://github.com/guoew/openvpn-install.git) u- O7 h9 N- @
  2. # cd openvpn-install &&  bash openvpn-install.sh
    0 ^% K, D: u( p% U9 r
  3. Welcome to this OpenVPN "road warrior" installer!1 _6 l+ q1 d  @& w9 j' \, z
  4. 1 a; C3 ^( Z# a$ O
  5. I need to ask you a few questions before starting the setup.
    . p, x% a8 ^5 y3 g8 X
  6. You can leave the default options and just press enter if you are ok with them.
    & f7 |9 K1 v/ i2 |
  7. 6 i. n3 s, ~4 i  a
  8. First, provide the IPv4 address of the network interface you want OpenVPN' S1 h, J' O5 {! k
  9. listening to.2 M; o, O0 J' j* H" F- G8 |
  10. IP address: 172.27.0.2 #默认获取本机ip,直接回车
    ! g) A8 Q& K$ J5 U7 o

  11. 9 N, o- A' D$ c1 `- s/ R5 t7 q
  12. This server is behind NAT. What is the public IPv4 address or hostname?3 N/ z# {+ C* g! ~, c7 ^0 K0 Z' w
  13. Public IP address / hostname: 18.24.64.250 #输入主机公网ip2 E2 M  j% {2 Z9 o- j! Q; D

  14. # M) P* @1 C+ ?2 M6 B8 n+ X# d
  15. Which protocol do you want for OpenVPN connections?
    , D/ M: F4 t, l+ I9 f
  16.    1) UDP (recommended)2 ?- V$ p7 A+ z0 Z3 n0 n, v4 o
  17.    2) TCP
    & s) K9 c' p1 n* `5 I& |. v
  18. Protocol [1-2]: 1 #选择连接协议8 ~% n5 Q2 T! E+ i

  19. ( `0 ?4 _# H7 x' M
  20. What port do you want OpenVPN listening to?
    , k: |6 g' R! m6 A
  21. Port: 1194 #设置openvpn监听端口
    / R9 u/ X7 v! m" ~" V% b
  22. ; P6 n4 y# D% C2 T9 L  I
  23. Which DNS do you want to use with the VPN?: }0 k0 y; F$ z$ v, E  o
  24.    1) Current system resolvers: E; Z. p; t& u. K! Z
  25.    2) 1.1.1.1, B% U/ B* s4 s: d. P8 F% v7 \
  26.    3) Google  b3 F# r  L7 _
  27.    4) OpenDNS0 q8 l. v( A" x! k2 }4 j! T  `) S
  28.    5) Verisign
    ' o& L, i4 X( C) F- I. K0 R* r
  29. DNS [1-5]: 1 #选择DNS. O$ m  u) ^8 }! t, N3 r
  30. ) s8 U  J& b7 f' t
  31. Finally, tell me your name for the client certificate.
    ' f* N" O2 Z! @; ?
  32. Please, use one word only, no special characters.
      p5 d  \& C% ^
  33. Client name: client #设置客户端名称5 G# M* P8 S3 |! h
  34. . A/ C- t/ X, Q  a
  35. Okay, that was all I needed. We are ready to set up your OpenVPN server now.5 N; H& p! G; Q, `" R  u3 N9 N0 a, J
  36. Press any key to continue... #任意键继续
    6 Y% Q. y- t. J- g
  37. ...; y7 S2 c9 h7 q
  38. An updated CRL has been created.
    8 ?0 I( `* b, J# B* Y( X
  39. CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem! T% j& G$ U( g1 V

  40. ) B) A! o/ P1 V
  41. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service.
    ! P5 r6 _: j; l: p! O) F- G
  42. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-server@server.service → /lib/systemd/system/openvpn-server@.service.; `( g8 _" C9 T. x* ?  y6 f/ b

  43. 7 |; S4 M/ P! z! E! ]8 P5 v
  44. Finished!  #最终看到Finished时表示安装完毕
    $ m# ~6 `4 Z/ Z9 l& o% G  a$ k
  45. 1 O. H6 H/ y( F  m2 x% F% F- L
  46. Your client configuration is available at: /root/client.ovpn #客户端配置文件路径
    " Q7 |5 I* [7 q: b2 g  D
  47. If you want to add more clients, you simply need to run this script again! 5 C9 |5 |, d# e2 S
复制代码
将客户端配置文件 /root/client.ovpn,下载到本地以备客户端使用1 o! s  ^* ]: W% i+ H2 f
1.2. 添加账号在openvpn目录下的userfile.sh中添加用户和密码,以空格隔开
! l$ w) S! C; T' i( C
  1. # cat /etc/openvpn/userfile.sh
    & `4 q1 X: j4 m) r
  2. guoew guoew123
    ; y9 q7 X+ V* L9 s! t9 Q
  3. yakexi yakexi123" @4 D0 W  Y7 E- }+ q, t7 [" m
复制代码
截止现在一个超级简单的openvpn服务就已经搭建好了,接下来将使用客户端连接openvpn服务器(以win10为例)- a) t( d8 E1 X
二. 客户端部署使用2.1. 安装openvpn客户端2.2. 配置客户端将安装好的客户端打开,点击Import file 把准备好的客户端配置文件导入进去。2 p) I4 D* o+ n1 l
2.3. 连接openvpn服务器打开客户端,点击Connect,使用服务器端已添加的账号登录# V; F7 I/ l; P  g1 v) ]5 S1 l, Z

END
% ?2 E7 u) i" x附:安装完毕后,再次执行脚本openvpn-install.sh 会有四个菜单选项(添加、撤销、卸载、退出),可根据自身实际情况应用,如下:
% T. N( H3 R, x# e9 ?0 v: \9 d6 U
  1. Looks like OpenVPN is already installed.
    - l% m' p6 u' T, d, C
  2. 5 o0 k; Z1 G! x. d" w- A8 w3 u
  3. What do you want to do?
    + B" n3 @2 M' }
  4.    1) Add a new user- f5 m- K# {0 f, J% O+ Z0 }5 i# O
  5.    2) Revoke an existing user
    3 A6 n6 F: B- |* g/ ]  j# z
  6.    3) Remove OpenVPN+ X8 a2 d1 w( @3 d' P
  7.    4) Exit
    1 m8 U/ E. h1 e, v! E; z
  8. Select an option [1-4]:- c- R+ L$ E: E9 f$ U9 f# Z
复制代码
, ^5 V, B  g) g; X& e
这里有个不足之处是,当使用多证书时,账号是通用的。即同一个账号,可以应用于不同的证书。' d6 j) N! x, f
如果想要不同用户使用不同的证书进行登录[无账号],欢迎访问原项目地址:  j( q) V' X5 _; J# |8 h
https://github.com/Nyr/openvpn-install$ d' f. \% r) E+ E
) B8 y! F7 E1 N2 h* o/ P
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|

GMT+8, 2025-11-5 01:50 AM , Processed in 0.108330 second(s), 23 queries .

Powered by xyh-moon X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表