linux pptp设置账号不能同时登录 查询已登录用户

查询已登录用户

找到"/etc/pptpd.conf"这个文件, 让下面这行生效:

# TAG: logwtmp
#       Use wtmp(5) to record client connections and disconnections.
#
logwtmp

查询在线用户

last|grep ppp|grep gone

在这里插入图片描述
搜索关键词是gone 我看别人都是搜still的 而我的服务器已登录的用户显示gone - no logout
我也不知道是什么问题。欢迎大神评论区指出
如果搜gone不行的话就换成still试试
在这里插入图片描述

禁止同一账号同时登录

有两种模式供大家选择

挤号模式

在/etc/ppp/ip-up文件末尾加上这一段

#挤号模式 第二个用户登录后断开第一个用户的连接
KEYWORD="gone"
NUMLOGINS=`last | grep ppp | grep $KEYWORD | grep -c "^$PEERNAME "`
if [ $NUMLOGINS -gt 1 ]; then
  DEVICE=$(last | grep ppp |grep $KEYWORD | sed -n 2p | awk '{print $2}')
  PID=$(cat /var/run/$DEVICE.pid)
  if [ $PID ]; then
    kill $PID
  fi
fi

非挤号模式

#非挤号模式 第二个用户无法登录连接
KEYWORD="gone"
NUMLOGINS=`last | grep ppp | grep $KEYWORD | grep -c "^$PEERNAME "`
if [ $NUMLOGINS -gt 1 ]; then
  PID=$(cat /var/run/$PPP_IFACE.pid)
  if [ $PID ]; then
    kill $PID
  fi
fi

最后奉上我的/etc/ppp/ip-up

#!/bin/sh
#
# This script is run by the pppd after the link is established.
# It uses run-parts to run scripts in /etc/ppp/ip-up.d, so to add routes,
# set IP address, run the mailq etc. you should create script(s) there.
#
# Be aware that other packages may include /etc/ppp/ip-up.d scripts (named
# after that package), so choose local script names with that in mind.
#
# This script is called with the following arguments:
#    Arg  Name                          Example
#    $1   Interface name                ppp0
#    $2   The tty                       ttyS1
#    $3   The link speed                38400
#    $4   Local IP number               12.34.56.78
#    $5   Peer  IP number               12.34.56.99
#    $6   Optional ``ipparam'' value    foo

# The  environment is cleared before executing this script
# so the path must be reset
PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin
export PATH

# These variables are for the use of the scripts run by run-parts
PPP_IFACE="$1"
PPP_TTY="$2"
PPP_SPEED="$3"
PPP_LOCAL="$4"
PPP_REMOTE="$5"
PPP_IPPARAM="$6"
export PPP_IFACE PPP_TTY PPP_SPEED PPP_LOCAL PPP_REMOTE PPP_IPPARAM

# as an additional convenience, $PPP_TTYNAME is set to the tty name,
# stripped of /dev/ (if present) for easier matching.
PPP_TTYNAME=`/usr/bin/basename "$2"`
export PPP_TTYNAME 

# If /var/log/ppp-ipupdown.log exists use it for logging.
if [ -e /var/log/ppp-ipupdown.log ]; then
  exec > /var/log/ppp-ipupdown.log 2>&1
  echo $0 $@
  echo
fi

# This script can be used to override the .d files supplied by other packages.
if [ -x /etc/ppp/ip-up.local ]; then
  exec /etc/ppp/ip-up.local "$@"
fi

run-parts /etc/ppp/ip-up.d \
  --arg="$1" --arg="$2" --arg="$3" --arg="$4" --arg="$5" --arg="$6"

# if pon was called with the "quick" argument, stop pppd
if [ -e /var/run/ppp-quick ]; then
  rm /var/run/ppp-quick
  wait
  kill $PPPD_PID
fi


#同一账号不能同时登录
sleep 2
#搜索关键词 不行就换成still
KEYWORD="gone"
STATUS="登录"
NUMLOGINS=`last | grep ppp | grep $KEYWORD | grep -c "^$PEERNAME "`


#挤号模式 第二个用户登录后断开第一个用户的连接
if [ $NUMLOGINS -gt 1 ]; then
  DEVICE=$(last | grep ppp |grep $KEYWORD | sed -n 2p | awk '{print $2}')
  PID=$(cat /var/run/$DEVICE.pid)
  if [ $PID ]; then
    kill $PID
    STATUS="登录成功-挤号"
  fi
fi

#非挤号模式 第二个用户无法登录连接
#if [ $NUMLOGINS -gt 1 ]; then
#  PID=$(cat /var/run/$PPP_IFACE.pid)
#  if [ $PID ]; then
#    kill $PID
#    STATUS="登录失败-挤号"
#  fi
#fi

echo `date -d today +"%F %T"` $PEERNAME $PPP_IFACE $PPP_REMOTE $PPP_IPPARAM $STATUS  >> /var/log/pptpd.log


若有不正之处,请多多谅解并欢迎指正。

参考:https://www.cnblogs.com/jcli/p/3960026.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值