创建auth-up文件

  1. vi /etc/ppp/auth-up
  2. chmod a+x /etc/ppp/auth-up

auth-up脚本内容如下

  1. #!/bin/sh
  2. # get the username/ppp line number from the parameters
  3. REALDEVICE=$1
  4. USER=$2
  5. # create the directory to keep pid files per user
  6. mkdir -p /var/run/pptpd-users
  7. # if there is a session already for this user, terminate the old one
  8. if [ -f /var/run/pptpd-users/$USER ]; then
  9. kill -HUP `cat /var/run/pptpd-users/$USER`
  10. rm /var/run/pptpd-users/$USER
  11. fi
  12. # copy the pid file of current user to /var/run/pptpd-users
  13. cp "/var/run/$REALDEVICE.pid" /var/run/pptpd-users/$USER

流程如下:

1.用户登录判断是否有/var/run/pptpd-users/用户名的文件

2.如果有平滑重启这个vpn用户进程,如果没有创建这个文件,文本里面有用户进程ID

3.老的连接被踢掉,新的连接可以使用

备注:这种模式下,一个账号只允许一个用户使用。

重启pptpd

  1. service pptpd restart

下边是原文

链接地址:http://poptop.sourceforge.net/dox/skwok/poptop_ads_howto_12.htm#oneconnection

By default, a user can make multiple connections to the pptpd server. To restrict one connection per user, create two script files in the /etc/ppp directory. When the same user logs in twice, the first connection will be disconnected. This is actually done on the ppp level, not with the pptpd.

The first file is /etc/ppp/auth-up

  1. #!/bin/sh
  2. # get the username/ppp line number from the parameters
  3. PPPLINE=$1
  4. USER=$2
  5. # create the directory to keep pid files per user
  6. mkdir -p /var/run/pptpd-users
  7. # if there is a session already for this user, terminate the old one
  8. if [ -f /var/run/pptpd-users/$USER ]; then
  9. kill -HUP `cat /var/run/pptpd-users/$USER`
  10. rm /var/run/pptpd-users/$USER
  11. fi
  12. # write down the username in the ppp line file
  13. echo $USER > /var/run/pptpd-users/$PPPLINE.new

The second file is /etc/ppp/ip-up.local

  1. #!/bin/sh
  2. REALDEVICE=$1
  3. # Get the username from the ppp line record file
  4. USER=`cat /var/run/pptpd-users/$REALDEVICE.new`
  5. # Copy the ppp line pid
  6. cp "/var/run/$REALDEVICE.pid" /var/run/pptpd-users/$USER
  7. # remove the ppp line record file
  8. rm "/var/run/pptpd-users/$REALDEVICE.new"

The method presented here may not be the best one, but it works for me. (If you have a better way, please let me know.)

PPTP VPN 限制一个账号只允许一个用户来登录的更多相关文章

  1. Java中一个方法只被一个线程调用一次

    1.想在运行时抛出异常,终止方法的运行 private final Set<Long> THREADS = new HashSet<>(); public void someM ...

  2. dedecms--二次开发文章内容页未登录禁止访问和同一个帐号只允许一个ip登录

    最近在用dedecms二次开发会员功能,领导要求,会员未登录不允许访问文章内容页,和同一个账号只允许一个ip登录,我是将这两个在一起判断的,判断session存不存在,不存在的情况下就是未登录,这时候 ...

  3. ftp 一个账号多个家目录的解决方案

    通常,配置ftp时,一个ftp账号只对应一个家目录,不能有多个家目录的情况. 但是,根据公司开发项目的需求,需要做到一个ftp对应多个开发目录.有想过创建软链接的,可是发现通过ftp是访问不了的. 举 ...

  4. vc++高级班之窗口篇[4]---让程序只运行一个实例

      大家都看过或者使用过类似只运行一个实例的程序,比如:QQ游戏.部分浏览器 等等! 让一个程序只运行一个实例的方法有多种,但是原理都类似,也就是在程序创建后,有窗口的程序在窗口创建前, 检查系统中是 ...

  5. 转载 - Vultr VPS注册开通且一键快速安装PPTP VPN和电脑连接使用

    本文转载来自:https://www.vultrclub.com/139.html 从2014年Vultr VPS进入市场之后,作为有背景.实力的搅局者,是的最近两年VPS.服务器的用户成本降低.配置 ...

  6. 从米家到 HomeKit,你只需要一个树莓派

    转载:从米家到 HomeKit,你只需要一个树莓派 2017.10.21 该教程针对 Raspbian Stretch (8 月起基于新版 Debian 的系统)更新,请注意文章中提示 Stretch ...

  7. win7系统的右键菜单只显示一个白色框不显示菜单项 解决办法

    如上图所示,桌面或其他大部分地方点击右键菜单,都只显示一个白色框,鼠标移上去才有菜单项看,并且效果很丑 解决办法: 计算机-右键-属性-高级-性能-设置-视觉效果-淡入淡出或滑动菜单到视图,将其前面的 ...

  8. Android 只开启一个Activity实例

    在一个Activity中,多次调用startActivity()来启动另一个Activity,要想只生成一个Activity实例,方法有两种. 方法一:设置起动模式 一个Activity有四种启动模式 ...

  9. form表单里如果只存在一个文本框,enter键提交

    在这里说一说浏览器里form表单的默认行为 我们都知道浏览器是存在很多默认行为的,可能是出于常用行为考虑又或者是历史原因.但有时候我们不需要这些默认行为.以下: 1).当form表单里只存在一个inp ...

随机推荐

  1. centos 7 + mono + jexus 环境安装

    1.安装 mlocate yum list|grep locate yum install mlocate.x86_64 updatedb 2.安装 yum-utils yum list|grep y ...

  2. Ubuntu 14.04下Django+MySQL安装部署全过程

    一.简要步骤.(Ubuntu14.04) Python安装 Django Mysql的安装与配置 记录一下我的部署过程,也方便一些有需要的童鞋,大神勿喷~ 二.Python的安装 由于博主使用的环境是 ...

  3. python3+ 模块学习 之 subprocess

    subprocess 模块方法: call() check_call() check_output() 以上三个方法用于创建一个子进程,父进程等待子进程结束.若shell = true, 则shell ...

  4. AX7: CREATE AN AUTOMATED TEST PACKAGE\MODEL

    AX7: CREATE AN AUTOMATED TEST PACKAGE\MODEL It’s really important for a stable solution the use of a ...

  5. NOIP2008 传纸条

    题目描述 小渊和小轩是好朋友也是同班同学,他们在一起总有谈不完的话题.一次素质拓展活动中,班上同学安排做成一个m行n列的矩阵,而小渊和小轩被安排在矩阵对角线的两端,因此,他们就无法直接交谈了.幸运的是 ...

  6. iOS 趣谈设计模式——通知

    [前言介绍] iOS的一种设计模式,观察者Observer模式(也叫发布/订阅,即Publich/Subscribe模式). 观察者模式,包含了通知机制(notification)和KVO(Key-v ...

  7. html特殊字符 编码css3 content:"我是特殊符号"

    项目中用到的一些特殊字符和图标 html代码 <div class="cross"></div> css代码 .cross{ width: 20px; he ...

  8. c#全局鼠标事件以及鼠标事件模拟

    最近在编写Max插件时,其主容器FlowLayoutPanel由于隐藏了滚动条,要实现按住鼠标中键上下拖动的功能,因此尝试了全局鼠标事件.以及鼠标勾子,可惜由于Max不争气?都未能实现,于是代码报废, ...

  9. 稳定灵活的 HTML 列式布局

    主要特点: 所有列轻松实现相同高度 兼容性极高 ------------------------------------------------ 代码 ------------------------ ...

  10. springboot一个service内组件的加载顺序

    先加载自身构造器,所以在构造器中初始化时若使用需要注入的(即@Autowired注解的)组件相关的方法,则会报null: 然后加载注入的组件即@Autowired 最后加载@PostConstruct ...