centos7怎么禁止root登录及sshd端口自定义
发表于:2024-09-22 作者:千家信息网编辑
千家信息网最后更新 2024年09月22日,这篇"centos7怎么禁止root登录及sshd端口自定义"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下
千家信息网最后更新 2024年09月22日centos7怎么禁止root登录及sshd端口自定义
这篇"centos7怎么禁止root登录及sshd端口自定义"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇"centos7怎么禁止root登录及sshd端口自定义"文章吧。
1.新建用户wwweee000
[root@localhost ~]# useradd wwweee000[root@localhost ~]# passwd wwweee000changing password for user wwweee000.new password:bad password: the password is a palindromeretype new password:passwd: all authentication tokens updated successfully.
2.#port 22字段删掉,将22改为其他不被使用的端口,服务器端口最大可以开到65536.//注意port是大写的"p"
[root@localhost ~]# cat -n /etc/ssh/sshd_config|grep "port *" 17 #port 22 100 #gatewayports no[root@localhost ~]# cat /etc/ssh/sshd_config|grep -n "port *"17:#port 22100:#gatewayports no[root@localhost ~]# awk "/port */" /etc/ssh/sshd_config#port 22#gatewayports no
上面还是不能满足输出结果:我们只要port 22的答案.
[root@localhost ~]# cat /etc/ssh/sshd_config|grep -n "port\ " 17:#port 22[root@localhost ~]# cat -n /etc/ssh/sshd_config|grep "port\ " 17 #port 22[root@localhost ~]# cat /etc/ssh/sshd_config|grep -n "port\ " 17:#port 22[root@localhost ~]# awk "/port\ /" /etc/ssh/sshd_config #port 22[root@localhost ~]# sed -i "17s/#port 22/port 22/g" /etc/ssh/sshd_config [root@localhost ~]# awk "/port\ /" /etc/ssh/sshd_config port 22
-n显示行号;\反斜杠实质定义
3.不使用vi/vim进行修改port 22 为 4096
[root@localhost ~]# sed -i "17s/port 22/port 4096/g" /etc/ssh/sshd_config [root@localhost ~]# cat /etc/ssh/sshd_config|grep "port\ "port 4096
4.修改 #permitrootlogin yes 为 permitrootlogin no
[root@localhost ~]# cat -n /etc/ssh/sshd_config|grep "permitrootlogin" 49 #permitrootlogin yes 104 # the setting of "permitrootlogin without-password".[root@localhost ~]# sed -i "49s/#permitrootlogin yes/permitrootlogin no/g" /etc/ssh/sshd_config[root@localhost ~]# cat -n /etc/ssh/sshd_config|grep "permitrootlogin no" 49 permitrootlogin no
5.重启sshd服务
[root@localhost ~]# systemctl restart sshd.service
6.使用 wwweee000 用户登录变化
[wwweee000@localhost ~]$
user普通用户不能编辑/etc/ssh/sshd_config
,需要切换root才能编辑,切换root命令 : su
7.root进行运行,编写shell脚本。//脚本通用centos 7 (主要:sshd_config端口号定义输入对root登录禁止)
#!/bin/bashsshd_port=`cat /etc/ssh/sshd_config|grep "port\ "`echo " 当前sshd端口:$sshd_port"read -ep " 请输入sshd服务的连接端口port (1-65536); 请确保其他端口冲突和防火墙端口开放业务:" sshd_port_readecho " 你输入的端口号:$sshd_port_read"sed -i "s/$sshd_port/port $sshd_port_read/g" /etc/ssh/sshd_configecho " 已经设置端口为:`cat /etc/ssh/sshd_config|grep "port\ "`"sed -i "s/#permitrootlogin yes/permitrootlogin no/g" /etc/ssh/sshd_configsystemctl restart sshd.serviceexit 0
运行测试(可循环使用)本次防火墙关闭/生产服务器都是关闭防火墙的
[root@localhost wwweee000]# firewall-cmd --state not running[root@localhost ~]# sh sshd_config_port.sh 当前sshd端口:port 22 请输入sshd服务的连接端口port (1-65536) 请确保其他端口冲突和防火墙端口开放业务:4096 你输入的端口号:4096 已经设置端口为:port 4096
以上就是关于"centos7怎么禁止root登录及sshd端口自定义"这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注行业资讯频道。
端口
登录
内容
服务
输入
防火墙
防火
口号
用户
业务
文章
服务器
知识
篇文章
脚本
冲突
切换
开放
运行
普通
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
软件开发与项目管理方向
虎符网络安全ukex全球站
达梦数据库分区管理界面
民政厅网络安全
sql数据库服务错误7031
龙源网与龙源数据库
最新阿里云服务器管理指南
数据库的物理结构设计论文格式
西安市网络安全保卫支队电话
服务器怎么分区
四川自然资源地理空间数据库建设
连接远程服务器time out
如何查找access数据库
数据库 知乎
崇明区海航软件开发代理商
软件开发课程海报配色
网络安全致家长的信
河南阡陌网络技术有限公司
网络技术 信息窃听
网络安全等级保护条例2.0下载
乐至软件开发工资一般多少钱
联想服务器管理口怎么登录
合肥兼职软件开发
郑州朝之夕网络技术
提供同行评审的数据库
安阳幼师网络安全
ncbi数据库简介
服务器 opengl
沽源县网络安全检查
太一互联网科技