当前位置:网站首页>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
边栏推荐
- 文字组合,不重复,做搜索或查询关键字匹配
- MySQL数据库讲解(九)
- 容灾有疑问?点这里
- Visio画拓扑图随记
- mysql 5.1升级到5.68
- VMWare安装64位XP中文教程
- elk安装
- 使用DialogFragment的一些感受及防踩坑经验(getActivity、getDialog为空,cancelable无效等)
- A table splitting implementation scheme of MySQL and InnoDB, MyISAM and MRG_ Introduction to MyISAM and other engine application scenarios
- Introduction to the use of semaphore for inter thread control
猜你喜欢
logback-logger和root
Jira截取全图
krpano全景之vtour文件夹和tour
处理 mkdir:无法创建目录“aaa“:只读文件系统
政务云迁移实践 北明数科使用HyperMotion云迁移产品为某政府单位实施上云迁移项目,15天内完成近百套主机迁移
Use the executors class to quickly create a thread pool
About the configuration and use of json5 in nodejs
Recyclerview advanced use (I) - simple implementation of sideslip deletion
Win10 comes with groove music, which can't play cue and ape files. It's a curvilinear way to save the country. It creates its own aimpack plug-in package, and aimp installs DSP plug-in
统信UOS PHP7.2.3升级至PHP7.2.24
随机推荐
处理 mkdir:无法创建目录“aaa“:只读文件系统
MySQL数据库讲解(七)
How to do a project easily
时间复杂度计算举例
rsync+inotify远程同步
多云数据流转?云上容灾?年前最后的价值内容分享
Operation instructions of star boundary automatic text translator (advanced version)
RecyclerView进阶使用-实现仿支付宝菜单编辑页面拖拽功能
困扰多年的系统调研问题有自动化采集工具了,还是开源免费的
HyperBDR云容灾V3.3.0版本发布|容灾功能升级,资源组管理功能优化
RecyclerView细节研究-RecyclerView点击错位问题的探讨与修复
OpenStack如何跨版本升级
关于NodeJS中JSON5的相关配置和使用
ActiveMq基础知识
编译Openssl
网页自适应,等比缩放
Pass in external parameters to the main function in clion
ie8 浏览器提示是否 阻止访问js脚本
man man随记和crontab的@reboot用法
Storage path of mod subscribed by starbound Creative Workshop at Star boundary