1.新建用户wwweee000
[root@localhost ~]# useradd wwweee000 [root@localhost ~]# passwd wwweee000 Changing password for user wwweee000. New password: BAD PASSWORD: The password is a palindrome Retype 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 22 100:#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/bash sshd_Port=`cat /etc/ssh/sshd_config|grep "Port\ "` echo " 当前sshd端口:$sshd_Port" read -ep " 请输入sshd服务的连接端口Port (1-65536); 请确保其他端口冲突和防火墙端口开放业务:" sshd_Port_read echo " 你输入的端口号:$sshd_Port_read" sed -i "s/$sshd_Port/Port $sshd_Port_read/g" /etc/ssh/sshd_config echo " 已经设置端口为:`cat /etc/ssh/sshd_config|grep "Port\ "`" sed -i "s/#PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config systemctl restart sshd.service exit 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 | 禁止 root登录及sshd端口脚本定义,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
更新日志
- 伍佰 《光环摇滚之声DSD》[WAV+CUE][500MB]
- 王菲.1999-只爱陌生人【EMI百代】【WAV+CUE】
- 林美音.1993-酒后的心声【瑞华】【WAV+CUE】
- 群星.2024-凡人歌电视剧原声带【正午阳光】【FLAC分轨】
- 黑神话悟空上品骨悚然精魄获取方法一览|上品骨悚然精魄收集攻略
- 《演灭Evotinction》正式登陆多平台发售!带你进入科幻潜行新境界
- 命运圣契2024公测最新兑换码大全 命运圣契开服可用兑换码汇总
- 银霞.1979-《回答·兰花草》新加坡限量复黑版[WAV+CUE]
- 王菲.1996-《乐乐精逊SACD日本限量版[WAV+CUE]
- 王菲.1996-《乐乐精逊SACD日本限量版[WAV+CUE]
- 不止黑神话!杭州给原创企业真金白银扶持 打造“杭州游戏”品牌
- 很有多样性:《战锤》首次引入非二元性别角色
- 《少女前线2:追放》项目组将裁员 官方:进一步优化组织结构
- 陈慧琳.2002-闪亮每一天新歌+精选2CD【正东】【WAV+CUE】
- 袁培华.1992-有缘【歌林】【WAV+CUE】