创建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. yum:在Red Hat和Fedora中使用

    1.列出已安装包: yum list installed--------->输出的结果可能在屏幕上一闪而过.所以最好把已安装包的列表重定义到一个文件中.然后是使用more/less查看 yum ...

  2. source 源码下载

    http://blog.csdn.net/zlgydx/article/details/50781258 经常需要查看某些第三方的源码,一直在用的一个网站,功能比较简介.好用. http://grep ...

  3. spring JPA 动态查询

    没什么好说的,记住就行. 下面是在Service中的方法 Page<TStaff> staffs=dao.findAll(new Specification<TStaff>() ...

  4. NGUI的localPosition和Position之间的关系

    假设有子节点为child, 父节点为parent, 且都是Transform类型. 则: child.localPosition = (child.position - parent.position ...

  5. C#获取网页内容的三种方式

    C#通常有三种方法获取网页内容,使用WebClient.WebBrowser或者HttpWebRequest/HttpWebResponse... 方法一:使用WebClient (引用自:http: ...

  6. pycharm激活码,拿走不谢

    激活码 新下载pycharm编辑器以后,会遇到一个激活的问题,否则只能试用30天 43B4A73YYJ-eyJsaWNlbnNlSWQiOiI0M0I0QTczWVlKIiwibGljZW5zZWVO ...

  7. LeetCode 135 Candy(贪心算法)

    135. Candy There are N children standing in a line. Each child is assigned a rating value. You are g ...

  8. jquery 调用函数时加()和不加()的执行顺序是不同的

    编写JQUERY(3.0,向下兼容3.0)代码当我们调用一个函数时可以不加括号,但加括号与不加括号是不同的.如下代码: $(function(){ a(b);//先打印a 再打印 b a(b());/ ...

  9. 1219 spring3 项目总结

    Spring3 项目总结 列志华 (组长) http://www.cnblogs.com/liezhihua/ 团队guihub https://github.com/LWHTF/OrderingFo ...

  10. spring3 项目更新

    列志华 (组长) http://www.cnblogs.com/liezhihua/ 团队guihub https://github.com/LWHTF/OrderingFood 黄柏堂 http:/ ...