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

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

[复制链接]

991

主题

92

回帖

5万

积分

管理员

积分
55457
发表于 2022-6-22 10:34:02 | 显示全部楼层 |阅读模式
一. 服务器端部署项目地址:https://github.com/guoew/openvpn-install
2 g$ ~1 L0 {7 z% k; O: f1.1. 下载安装
$ M+ F- V4 M8 y' }  B- ~' @) b
  1. # git clone https://github.com/guoew/openvpn-install.git
    7 m! L) i+ Q% L6 d* G2 g
  2. # cd openvpn-install &&  bash openvpn-install.sh0 d& F0 }* O. c/ C* Z) z
  3. Welcome to this OpenVPN "road warrior" installer!
    & H0 S. P8 ^+ C4 u

  4. 7 W) V9 R% }! j
  5. I need to ask you a few questions before starting the setup.$ [: _- i9 a8 Y3 L
  6. You can leave the default options and just press enter if you are ok with them.
    ! C6 d$ s8 x# k5 L

  7. " T, F  m# p8 R: S5 [" u2 M3 f
  8. First, provide the IPv4 address of the network interface you want OpenVPN
    1 O7 P! K9 x  D
  9. listening to.
    / K" v+ W2 G% U( t3 a8 P3 _
  10. IP address: 172.27.0.2 #默认获取本机ip,直接回车# K, o% N5 m1 U8 F9 X
  11. & p% X4 Q2 k' W9 J$ i
  12. This server is behind NAT. What is the public IPv4 address or hostname?$ s, A6 p! A; E8 v
  13. Public IP address / hostname: 18.24.64.250 #输入主机公网ip2 C7 E: ~0 T& ~
  14. 2 K# d( W% @. w6 ]9 ^
  15. Which protocol do you want for OpenVPN connections?4 q# X. d" T8 Q" {, W7 ]& I% C
  16.    1) UDP (recommended)$ p- u) Q' V1 B
  17.    2) TCP
    7 J% @) D3 H# V( ?1 J
  18. Protocol [1-2]: 1 #选择连接协议
    / U- x. Q  U4 e; q' _4 y

  19. ) P* C. ]; O' `! d/ F, p
  20. What port do you want OpenVPN listening to?) H% V; e4 d& l. I# [8 r" \. Z
  21. Port: 1194 #设置openvpn监听端口
    & x  P$ t* r; ^9 Y. F9 B

  22. % J: |9 O4 _- g. s
  23. Which DNS do you want to use with the VPN?
    6 w" w) J' Z) k4 C) U% t* H6 R
  24.    1) Current system resolvers
    $ V5 K. I+ B5 j! m/ k
  25.    2) 1.1.1.1
    7 C" I; ?" H/ ^* b& U+ K
  26.    3) Google
    " s2 K& ~) h. R4 G* X
  27.    4) OpenDNS
    / S4 D1 L: }0 j! ~
  28.    5) Verisign) z' S$ ]5 v5 s: w
  29. DNS [1-5]: 1 #选择DNS
    8 c8 _/ q- c  q1 i  a3 P
  30. " x  G% S5 D7 q1 T, v: H( o9 N
  31. Finally, tell me your name for the client certificate.1 m, I! g2 X) i
  32. Please, use one word only, no special characters.6 i# e3 K* o) W( `2 V% j4 w% }
  33. Client name: client #设置客户端名称% V5 M, {, z8 e: s9 f9 a

  34. : W: b0 }: X  M; L$ |  U
  35. Okay, that was all I needed. We are ready to set up your OpenVPN server now." F7 Z6 X; B8 e" y, @- g) \
  36. Press any key to continue... #任意键继续
    - c9 M6 u) Z' T, S- [' u
  37. ...
    * P  m5 ~$ R2 m6 ^$ g- v7 S
  38. An updated CRL has been created.
    9 Z2 q6 d2 e* i2 s. `
  39. CRL file: /etc/openvpn/server/easy-rsa/pki/crl.pem
    5 R. R  x+ c% Z; ]% f8 r

  40. - N0 [" l1 [. u( V
  41. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-iptables.service → /etc/systemd/system/openvpn-iptables.service.4 s+ w" A1 C3 O- P6 X
  42. Created symlink /etc/systemd/system/multi-user.target.wants/openvpn-server@server.service → /lib/systemd/system/openvpn-server@.service.
    ; X. F! v$ p$ t- \# {

  43. ( c- J6 s, p2 ^) y" |
  44. Finished!  #最终看到Finished时表示安装完毕# R/ ?" e, F  {: L

  45. ' L" ~$ m2 X- P4 F, x
  46. Your client configuration is available at: /root/client.ovpn #客户端配置文件路径+ E6 J7 {& ~- t4 N, i2 q% a
  47. If you want to add more clients, you simply need to run this script again! 8 R2 m) l( }' d0 s
复制代码
将客户端配置文件 /root/client.ovpn,下载到本地以备客户端使用2 x0 @5 m( H& A# m8 o* S3 I
1.2. 添加账号在openvpn目录下的userfile.sh中添加用户和密码,以空格隔开0 u  o/ D3 b- ~: Q: _1 A# H& {
  1. # cat /etc/openvpn/userfile.sh" f* X# {; A- _! j. n) r6 n# t
  2. guoew guoew123
    / C! ~( [9 n7 i! t7 S
  3. yakexi yakexi123
    ! `1 t( u- O4 y' D* f1 h
复制代码
截止现在一个超级简单的openvpn服务就已经搭建好了,接下来将使用客户端连接openvpn服务器(以win10为例)% a2 w6 M: M/ n1 Z/ X' v5 D
二. 客户端部署使用2.1. 安装openvpn客户端2.2. 配置客户端将安装好的客户端打开,点击Import file 把准备好的客户端配置文件导入进去。, l, g) X& c! ?) h8 s
2.3. 连接openvpn服务器打开客户端,点击Connect,使用服务器端已添加的账号登录
( z- _, E0 n2 F
END
0 U+ J5 H" h$ k& w/ _4 S附:安装完毕后,再次执行脚本openvpn-install.sh 会有四个菜单选项(添加、撤销、卸载、退出),可根据自身实际情况应用,如下:. m0 v3 g! g# n) t3 w2 S' }
  1. Looks like OpenVPN is already installed.
    3 }/ r$ d, P. [) w  z

  2. 9 r6 N# ?" @) y8 F. g$ x2 v  ^  J) y$ J
  3. What do you want to do?0 G2 s( U! S$ O; \3 |4 H, E
  4.    1) Add a new user
    3 ?5 I9 a" y3 H
  5.    2) Revoke an existing user
    % o: x/ ]# x6 T) S: N' ]
  6.    3) Remove OpenVPN2 V9 _- x9 D1 a' d" u5 ^
  7.    4) Exit5 }; }5 B6 ~) I; t* I$ m) I
  8. Select an option [1-4]:
    ) L: K1 L* @8 z3 g% U* s
复制代码

1 \# E& n' R$ L0 _$ N; ?这里有个不足之处是,当使用多证书时,账号是通用的。即同一个账号,可以应用于不同的证书。
1 d& {" i1 r$ E如果想要不同用户使用不同的证书进行登录[无账号],欢迎访问原项目地址:& F8 V2 t: A9 s1 t. h! q
https://github.com/Nyr/openvpn-install
. n) O* {# d. h! {5 x0 w+ F+ y* v. p3 Q9 v
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|

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

Powered by xyh-moon X3.5

© 2001-2026 Discuz! Team.

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