当前位置:网站首页>ssh限制登录的四种手段
ssh限制登录的四种手段
2022-04-23 14:10:00 【小灰墩墩】
ssh限制登录的四种手段
1、xinetd服务
配置/etc/hosts.allow和hosts.deny
[root@centos7 ~]# hostname -I
192.168.75.171
[root@centos7 ~]# vim /etc/hosts.allow
all:192.168.75.160:allow
all:192.168.75.1:allow #在虚拟机中操作,记得添加宿主机,要不ssh会中断,自杀
[root@centos7 ~]# cat /etc/hosts.deny
all:all:deny
[root@centos7 ~]# systemctl restart xinetd
[root@centos7 ~]# systemctl restart sshd
[root@CentOS6 ~]# hostname -I
192.168.75.160
[root@CentOS6 ~]# ssh [email protected]
[email protected]'s password:
Last login: Wed Nov 3 20:35:38 2021 from 192.168.75.160 #正常登录
[root@centos7 ~]#
[root@centos7 ~]# hostname -I
192.168.75.170
[root@centos7 ~]# ssh [email protected]
ssh_exchange_identification: read: Connection reset by peer #无法登录
2、iptables
# iptables -t filter -A INPUT -s 1.1.1.1 -d `hostname -I` -p tcp --dport 22 -j ACCEPT
# iptables -t filter -A INPUT -p tcp --dport 22 -j DROP
3、通过修改sshd_config配置文件AllowUsers实现
AllowUsers
这个指令后面跟着一串用空格分隔的用户名列表(其中可以使用"*"和"?"通配符)。默认允许所有用户登录。
如果使用了这个指令,那么将仅允许这些用户登录,而拒绝其它所有用户。
如果指定了 USER@HOST 模式的用户,那么 USER 和 HOST 将同时被检查。
这里只允许使用用户的名字而不允许使用UID。相关的 allow/deny 指令按照下列顺序处理:
DenyUsers, AllowUsers, DenyGroups, AllowGroups
[root@centos7 ~]# vim /etc/ssh/sshd_config
#末尾追加如下地址,每个地址用空格隔开
AllowUsers *@10.213.53.40 *@10.213.53.41 *@10.213.53.42 *@10.213.53.43 *@10.213.53.44 *@10.213.53.45 *@11.234.* *@11.2.2.*
[root@centos7 ~]# systemctl restart sshd
4、设定登录黑名单
[root@centos7 ~]# vi /etc/pam.d/sshd
#追加
auth required /lib/security/pam_listfile.so item=user sense=deny file=/etc/sshd_user_deny_list onerr=succeed
所有/etc/sshd_user_deny_list里面的用户被拒绝ssh登录
版权声明
本文为[小灰墩墩]所创,转载请带上原文链接,感谢
https://blog.csdn.net/swyer_66/article/details/121131690
边栏推荐
- 统信UOS卸载php7.2.24,安装php7.4.27 ;卸载再安装为PHP 7.2.34
- 逻辑卷创建与扩容
- Recyclerview advanced use (II) - simple implementation of vertical drag and drop sorting
- sar命令详解
- mysql 5.1升级到5.610
- MYSQL一种分表实现方案及InnoDB、MyISAM、MRG_MYISAM等各种引擎应用场景介绍
- STD:: map and STD:: vector memory free
- yml引用其他变量
- Algorithem_ReverseLinkedList
- Redis数据库讲解(一)
猜你喜欢

About the configuration and use of json5 in nodejs

HyperBDR云容灾V3.2.1版本发布|支持更多云平台,新增监控告警功能

How QT designer adds resource files

Operation instructions of star boundary automatic text translator (advanced version)

squid代理

man man随记和crontab的@reboot用法

倒计时1天~2022云容灾产品线上发布会即将开始

postman批量生产body信息(实现批量修改数据)

krpano全景之vtour文件夹和tour

剑指offer刷题(1)--面向华为
随机推荐
百度笔试2022.4.12+编程题目:简单整数问题
Pass in external parameters to the main function in clion
HyperMotion云迁移完成阿里云专有云产品生态集成认证
Recyclerview advanced use (II) - simple implementation of vertical drag and drop sorting
ie8 浏览器提示是否 阻止访问js脚本
星界边境文本自动翻译机使用说明
js 进度条,显示加载进度
redis数据库讲解二(redis高可用、持久化、性能管理)
MySQL数据库讲解(十)
uni-app消息推送
微信小程序轮播图swiper
pthread_ Why does self() repeat
How to do a project easily
返回数组排序后下标
About the configuration and use of json5 in nodejs
JDBC和servlet写CRUD的接口总结
RecyclerView高级使用(一)-侧滑删除的简单实现
yml引用其他变量
微信小程序将原生请求通过es6的promise来进行优化
js 键值判断