创建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. ORA-12519, ORA-00020异常产生原因及解决方案

    近期在做项目的过程中,使用oracle时碰到了如下两个异常: ORA-12519, TNS:no appropriate service handler found: ORA-00020:maximu ...

  2. 事实证明,abstract类除了不能用new实例化和类没什么区别

    abstract类是抽象类,不能够实例化,大家都知道,abstract类往往和接口interface一块儿使用,针对接口中一些公共的方法进行实现,然后实体类去继承抽象类和接口.虽然abstract类不 ...

  3. Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.

    问题: Azure Sql 在插入数据是出现“Msg 40054, Level 16, State 1, Line 2  Tables without a clustered index are no ...

  4. SOLID rule in JAVA design.

    Classes are the building blocks of your java application. If these blocks are not strong, your build ...

  5. Chrome插件概览(一) – The basics

    转载http://lvjava.com/?p=582 原文见https://developer.chrome.com/extensions/overview.html Chrome Extension ...

  6. onethink入门笔记(一)

    由于公司需求所以大概花了一个星期搞了一个一个基于onethink的数据管理平台demo不得不说onethink这个基于thinkphp3.2.3的框架还是很棒的 让我这个没基础过php的人也能在一星期 ...

  7. 0,SFDC 开发篇 - 开发框架和APEX语法

    1, 开发环境 Your Name | Developer Console | Debug | Open Execute Anonymous Window 输入hello world,并点击Excut ...

  8. webApi上传下载文件

    上传文件通过webApi html端调用时包含(form提交包含 enctype="multipart/form-data",才可以启作用获取到文件) public class U ...

  9. [python]获取文件夹下所有文件名

    #---picknames.py---import os filenames = os.listdir(os.getcwd()) for name in filenames: print(name)

  10. python Tab自动补全命令设置

    Mac/Windows下需要安装模块儿 pip install pyreadline pip install rlcompleter pip install readline 注意,需要先安装pyre ...