如何在centos 7中修改sshd
发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,这期内容当中小编将会给大家带来有关如何在centos 7中修改sshd,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。1.新建用户wwweee000[root@loc
千家信息网最后更新 2026年11月02日如何在centos 7中修改sshd
这期内容当中小编将会给大家带来有关如何在centos 7中修改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
上述就是小编为大家分享的如何在centos 7中修改sshd了,如果刚好有类似的疑惑,不妨参照上述分析进行理解。如果想知道更多相关知识,欢迎关注行业资讯频道。
端口
服务
输入
防火墙
防火
口号
用户
业务
内容
服务器
脚本
冲突
分析
切换
开放
登录
运行
普通
最大
专业
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
互联网科技工作委员会主任
互联网科技公司税收优惠
金诺互联网科技
互联网金融 科技
浩特互联网科技
汇久创客互联网科技
易通互联网络科技有限公司
成都狮子座互联网科技
哈尔滨新华互联网科技
上海电发互联网科技有限公司
新华互联网科技2019
以后互联网后是啥科技
互联网科技项目计划书材料类
港股科技和互联网
洛阳共同富裕互联网科技有限公司
合肥互联网科技公司公章图片
南通创西澳互联网科技有限公司
国产互联网科技公司
互联网科技平台产品运营
广州三三互联网科技有限公司
互联网科技垄断
关于新基建和互联网科技
银优互联网科技有限公司
天津摩尔互联网科技
互联网科技视频素材
汉立互联网科技有限公司联系电话
注册互联网科技公司经营范围大全
想开互联网科技公司怎么样
深圳市罗太互联网科技有限公司
互联网数据科技专业