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

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

[复制链接]

991

主题

92

回帖

5万

积分

管理员

积分
55457
发表于 2022-6-22 10:34:02 | 显示全部楼层 |阅读模式
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install8 u3 Z; r6 l; }- V( t
1.1. 下载安装
" f; v+ b) h9 B) X" e+ F
  1. # git clone https://github.com/guoew/openvpn-install.git
    0 y: }1 j. q8 A' U
  2. # cd openvpn-install &&  bash openvpn-install.sh( Z# c% \) T7 @& B% x
  3. Welcome to this OpenVPN "road warrior" installer!; C0 m7 Q$ d$ p3 x  a
  4. ; }# e9 s- Z, B1 x
  5. I need to ask you a few questions before starting the setup.
    7 J9 O: }& [* z/ Y* z3 A
  6. You can leave the default options and just press enter if you are ok with them.
    $ K1 ~. o! m, Q: x% f
  7. 6 {  L. x. N6 I9 U0 X0 M
  8. First, provide the IPv4 address of the network interface you want OpenVPN
    + b+ }1 t& g' h2 X
  9. listening to.
    % ^0 E+ ~" H3 u1 d* j
  10. IP address: 172.27.0.2 #默认获取本机ip,直接回车: K/ R. c# r0 R, z$ t/ J, j

  11. ! _9 Z2 R0 A0 R4 k/ Z. c/ j1 `3 D/ }
  12. This server is behind NAT. What is the public IPv4 address or hostname?- a2 [1 c/ g2 a/ X4 h* W3 A( Y
  13. Public IP address / hostname: 18.24.64.250 #输入主机公网ip. t6 m) d9 |& ^7 M8 i6 u
  14. ) p; U2 ]" X/ g& z
  15. Which protocol do you want for OpenVPN connections?
    , P  e+ X9 a5 i  q- s
  16.    1) UDP (recommended)
    * W( I' E3 e1 p
  17.    2) TCP
    ) X. e3 s% }( |0 _: W' I( O+ E
  18. Protocol [1-2]: 1 #选择连接协议
    ; o3 u/ Y0 u! K) F$ d( s
  19. 2 [  m  y1 F, g: X! k4 e: y
  20. What port do you want OpenVPN listening to?
    & p5 y5 u7 S8 R+ [9 f- G
  21. Port: 1194 #设置openvpn监听端口' T% T, D* Q+ B3 n  |

  22. 7 }; [# l  B% q  z  _8 v
  23. Which DNS do you want to use with the VPN?
    6 B! R  b/ s  u( [, s, T9 {
  24.    1) Current system resolvers' ]0 C) C* }1 N8 }/ S
  25.    2) 1.1.1.1: M7 s( I0 }' b
  26.    3) Google
    * V& g; K" H4 P% e$ t
  27.    4) OpenDNS
    5 x) c: X0 i( E$ f, p1 e- ]9 {* g
  28.    5) Verisign7 A1 D" C- i% O$ p* _  E/ _- J3 D
  29. DNS [1-5]: 1 #选择DNS; s/ k4 |7 a4 j- |5 a9 c: i

  30. + p) `! e  a. D
  31. Finally, tell me your name for the client certificate.
    : h4 R/ |4 J4 [; o
  32. Please, use one word only, no special characters.
    8 {  U3 \+ {. G2 B/ M0 u$ q
  33. Client name: client #设置客户端名称
    - V% c" d+ A) I7 Z. c2 H( e
  34. ! p6 G' L, H* p& P$ ]9 C
  35. Okay, that was all I needed. We are ready to set up your OpenVPN server now.
    ) L) Z- l' k! E  X
  36. Press any key to continue... #任意键继续% P$ \6 ?5 H, n$ ~2 x
  37. ...- r6 T0 l6 c3 j  ~6 H! Q5 [
  38. An updated CRL has been created.7 @4 v4 o* }  V! L9 L: ]
  39. CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem
    7 N1 J2 D' f( L9 G# n
  40. 1 a' W$ X, t& d' w$ s$ j/ |3 [( e' n; y
  41. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service.3 Z  D2 N9 L1 i- X6 E4 [
  42. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-server@server.service → /lib/systemd/system/openvpn-server@.service.5 C  S, o* T8 r8 ~" v

  43. " l' r3 X: Q5 h# y
  44. Finished!  #最终看到Finished时表示安装完毕; s* j2 @/ n& u: T

  45. + ~5 r3 j# D7 e, }: Y# V. Y/ Y
  46. Your client configuration is available at: /root/client.ovpn #客户端配置文件路径
    ! V7 X. T1 s0 y- `! w) C0 |4 @
  47. If you want to add more clients, you simply need to run this script again! * O+ h0 ~- G+ u- d* O4 o+ ]
复制代码
将客户端配置文件 /root/client.ovpn,下载到本地以备客户端使用
- Y9 ?$ ]& n, n1 N) Y1.2. 添加账号在openvpn目录下的userfile.sh中添加用户和密码,以空格隔开! {3 E* Z, b- T- X
  1. # cat /etc/openvpn/userfile.sh
    4 z, b( N& Z  D+ a
  2. guoew guoew123
    : k( i* I2 A. \  }
  3. yakexi yakexi1231 L+ U" f/ o0 ~* y1 f  F
复制代码
截止现在一个超级简单的openvpn服务就已经搭建好了,接下来将使用客户端连接openvpn服务器(以win10为例)
; I3 g! e8 ^! J1 _, y7 z二. 客户端部署使用2.1. 安装openvpn客户端2.2. 配置客户端将安装好的客户端打开,点击Import file 把准备好的客户端配置文件导入进去。
0 P0 }& i8 Z9 E4 F2.3. 连接openvpn服务器打开客户端,点击Connect,使用服务器端已添加的账号登录( [5 t& Z, b( ]! R1 O) _

END$ m1 v+ Z& K$ Q8 ]0 P
附:安装完毕后,再次执行脚本openvpn-install.sh 会有四个菜单选项(添加、撤销、卸载、退出),可根据自身实际情况应用,如下:
5 Y0 [# L# m6 O, W$ ~" x
  1. Looks like OpenVPN is already installed.- H1 m- o7 k/ l! W3 }
  2. 9 {' i9 c% b. \; N: V* c/ Q6 u
  3. What do you want to do?
    * D/ m) u3 a* |
  4.    1) Add a new user
    " v) T8 t+ h0 Z! P8 L  H2 _
  5.    2) Revoke an existing user
    , F$ j  z+ i1 U. ?8 I! H
  6.    3) Remove OpenVPN& \* i3 s! u( Q( r. v
  7.    4) Exit
    ( {% ]' P5 d$ {- W( ]
  8. Select an option [1-4]:
    + j6 ?8 p; m! e$ Q+ v) o
复制代码

& @% i; u8 B& P) Q. }: j% w  G# M这里有个不足之处是,当使用多证书时,账号是通用的。即同一个账号,可以应用于不同的证书。, p% U8 s2 l( M/ h. I$ k$ w
如果想要不同用户使用不同的证书进行登录[无账号],欢迎访问原项目地址:! P$ ?- u* }/ @/ ^+ K& b& F
https://github.com/Nyr/openvpn-install
: n! z& ^/ P) r  N" s
4 @6 z$ _& t0 k" B1 c: y1 j4 Q8 _
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|

GMT+8, 2026-8-5 10:19 AM , Processed in 0.094731 second(s), 22 queries .

Powered by xyh-moon X3.5

© 2001-2026 Discuz! Team.

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