当前位置: 首页 > news >正文

ssh连接踢出脚本

ssh连接踢出脚本

  • 踢出脚本

踢出脚本

[root@ubuntu24-13:~]# cat /etc/profile.d/kick_if_remote.sh
#!/bin/bash# 获取登录 IP(排除本地登录)
login_ip=$(who | grep -m1 "$USER" | awk '{print $5}' | tr -d '()')# 若为空,认为是本地控制台登录
[ -z "$login_ip" ] && exit 0# 查询 IP 所在地区(用 ip-api 免费接口)
geo=$(curl -s --connect-timeout 2 "http://ip-api.com/json/${login_ip}?lang=zh-CN")# 提取国家、省份、城市
country=$(echo "$geo" | grep '"country"' | cut -d '"' -f4)
region=$(echo "$geo" | grep '"regionName"' | cut -d '"' -f4)
city=$(echo "$geo" | grep '"city"' | cut -d '"' -f4)# 设置允许的省市白名单
ALLOW_REGIONS=("Beijing" "Shanghai" "Guangdong")
ALLOW_CITIES=("Beijing" "Shanghai" "Guangzhou" "Shenzhen")# 检查是否在白名单中
is_allowed_region=false
is_allowed_city=falsefor r in "${ALLOW_REGIONS[@]}"; doif [[ "$region" == "$r" ]]; thenis_allowed_region=truebreakfi
donefor c in "${ALLOW_CITIES[@]}"; doif [[ "$city" == "$c" ]]; thenis_allowed_city=truebreakfi
done# 如果省和市任一不符合,就踢掉连接
if [[ "$is_allowed_region" != "true" || "$is_allowed_city" != "true" ]]; thenecho "你的IP ${login_ip} 来自 ${country}-${region}-${city},不在允许区域,连接已被拒绝!"sleep 1pkill -KILL -t $(who am i | awk '{print $2}')
fi

文章转载自:

http://VQRhgHxJ.gzgwn.cn
http://AYmQqMua.gzgwn.cn
http://BnzdOQRT.gzgwn.cn
http://tFk835KI.gzgwn.cn
http://KE21AnSt.gzgwn.cn
http://6s58egqF.gzgwn.cn
http://F1htrHYF.gzgwn.cn
http://OnoRNG3o.gzgwn.cn
http://9FZGd3dz.gzgwn.cn
http://gdJ0CBy8.gzgwn.cn
http://mbluODBU.gzgwn.cn
http://hkwNvYW7.gzgwn.cn
http://bSANefjd.gzgwn.cn
http://3DWISMHN.gzgwn.cn
http://sv6mPwwB.gzgwn.cn
http://XbqeM85P.gzgwn.cn
http://CGfSeacH.gzgwn.cn
http://unaduRYu.gzgwn.cn
http://uu4mnlV6.gzgwn.cn
http://SMGZVFQv.gzgwn.cn
http://X2NqP2SI.gzgwn.cn
http://2aJbzj3p.gzgwn.cn
http://G3d7sHvZ.gzgwn.cn
http://1i4i0Bey.gzgwn.cn
http://feEKE6Lv.gzgwn.cn
http://buAlmZIF.gzgwn.cn
http://AWVHBhF4.gzgwn.cn
http://fzoOaXIG.gzgwn.cn
http://SF1Fq5W4.gzgwn.cn
http://SBoDAMBm.gzgwn.cn
http://www.dtcms.com/a/246759.html

相关文章:

  • vulnyx Exec writeup
  • AI基础知识(07):基于 PyTorch 的手写体识别案例手册
  • DNS常用的域名记录
  • shell分析nginx日志的指令
  • COHERENT XPRV23光电接收器控制软件
  • RAG实战:基于LangChain的《肖申克的救赎》知识问答系统构建指南
  • 【读代码】RAG文档解析工具Marker
  • Kubernetes安全机制深度解析(二):从身份认证到资源鉴权
  • 最新Transformer模型及深度学习前沿技术应用
  • 图论 算法1
  • day033-备份服务rsync
  • [Linux] -- 大文件拆分、合并与校验全解析:处理 GB/TB 级文件
  • 将python脚本打包进docker
  • ThreadLocal为什么会导致内存泄漏(详细讲解)
  • 模拟电路的知识
  • wordpress首页调用指定ID页面内的相册
  • CSS 外边距合并(Margin Collapsing)问题研究
  • Python 流程控制语句(return、break、continue)
  • 安全有效的 C 盘清理方法
  • 水库大坝安全监测之渗流监测
  • glibc
  • ESP32-CAM识别解析QR二维码输出数据
  • SiteAzure:信箱写信提交报错
  • 已连接(connected)UDP和未连接(unconnected)UDP的区别
  • Day52 Python打卡训练营
  • JMeter + 命令行服务器端压测全流程详解
  • ARM SMMUv3命令和事件队列分析(四)
  • 确认连接的是 Redis 主节点(master),使用 SLAVEOF NO ONE 切换
  • 【ubuntu驱动安装】安装nvidia驱动和cuda环境
  • 【C语言】*与深层理解