centos 7 修改sshd | 禁止 root登录及脚本定义
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 *"
#Port
#GatewayPorts no
[root@localhost ~]# cat /etc/ssh/sshd_config|grep -n "Port *"
:#Port
:#GatewayPorts no
[root@localhost ~]# awk "/Port */" /etc/ssh/sshd_config
#Port
#GatewayPorts no
上面还是不能满足输出结果:我们只要Port 22的答案.
[root@localhost ~]# cat /etc/ssh/sshd_config|grep -n "Port\ "
:#Port
[root@localhost ~]# cat -n /etc/ssh/sshd_config|grep "Port\ "
#Port
[root@localhost ~]# cat /etc/ssh/sshd_config|grep -n "Port\ "
:#Port
[root@localhost ~]# awk "/Port\ /" /etc/ssh/sshd_config
#Port
[root@localhost ~]# sed -i "17s/#Port 22/Port 22/g" /etc/ssh/sshd_config
[root@localhost ~]# awk "/Port\ /" /etc/ssh/sshd_config
Port
-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
4.修改 #PermitRootLogin yes 为 PermitRootLogin no
[root@localhost ~]# cat -n /etc/ssh/sshd_config|grep "PermitRootLogin"
#PermitRootLogin yes
# 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"
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
运行测试(可循环使用)本次防火墙关闭/生产服务器都是关闭防火墙的
[root@localhost wwweee000]# firewall-cmd --state
not running
[root@localhost ~]# sh sshd_config_Port.sh
当前sshd端口:Port
请输入sshd服务的连接端口Port (-)
请确保其他端口冲突和防火墙端口开放业务:
你输入的端口号:
已经设置端口为:Port
centos 7 修改sshd | 禁止 root登录及脚本定义的更多相关文章
- 配置sshd_config中的PermitRootLogin设置root登录或者禁止root登录
在etc的sshd_config文件中,默认有PermitRootLogin no的配置,这个的意思是禁止root用户登录,如果想要允许root登录,需要su root用户到sshd_config下进 ...
- ssh远程登录,禁止root登录
1,useradd xiaobingpasswd xiaobing (设置密码) 2,禁止root登陆,修改 /etc/ssh/sshd_configPermitRootLogin yes 改为 Pe ...
- centos aws 修改使用密码ssh登录
因为使用pem登录有很多局限性,在此修改为用密码但不是root登录 1.关闭selinux(要重启) vi /etc/selinux/config SELINUX=disabled 2.重置root密 ...
- centos 7 禁止root登录及更改ssh端口号
vim /etc/ssh/sshd_config PermitRootLogin yes => PermitRootLogin no systemctl restart sshd.service ...
- CentOS 如何修改mysql 用户root的密码
源地址:http://blog.sina.com.cn/s/blog_6756f85201019zv7.html 第一步:用帐号登录mysql[root@CentOs5 ~]# mysql -u ro ...
- Centos 打开ssh 密码验证 和 root 登录
# 1 打开系统的密码验证功能: vim /etc/ssh/sshd_config #允许使用密码登录(注释此行 就是允许证书登录) PasswordAuthentication yes # 2 打开 ...
- CentOS SSH安全和配置无密码登录
CentOS ssh默认监听端口 22端口,允许root用户ssh登录.server投入生产后很有必要更改默认ssh监听端口和禁止root登录. 步骤1:确认安装有ssh包 [appuser@su17 ...
- 允许Root登录Docker ubuntu(MAC主机,使用portainer管理)
1. 完成ubuntu容器的建立,完成ssh端口映射 2. 进入portainer内容器的console界面完成如下修改 a 刷新安装源:apt-get update b 安装sshd:apt-get ...
- linux禁止root用户直接登录sshd并修改默认端口
linux最高权限用户root,默认可以直接登录sshd.为了提高服务器的安全度,需要对它进行禁止,使得攻击者无法通过暴力破解来获取root权限. 1,新建一个用户: #useradd xxx (xx ...
随机推荐
- java练习---4
//程序员:罗元昊 2017.9.17 今天好累吖咦吖咦吖 package demo;import java.util.Scanner;public class Lk { public static ...
- VS、C#配置R语言开发环境
R语言学习笔记(一)——在Vs.C#中配置R语言开发环境. 最近在学习小众的R语言,所以将遇到的问题记录下来供大家参考,不足之处欢迎大家交流指正. 至于R语言的介绍就不多说了,它集成了复杂的数学算法, ...
- C++单继承、多继承情况下的虚函数表分析
C++的三大特性之一的多态是基于虚函数实现的,而大部分编译器是采用虚函数表来实现虚函数,虚函数表(VTAB)存在于可执行文件的只读数据段中,指向VTAB的虚表指针(VPTR)是包含在类的每一个实例当中 ...
- Mysql架构简要
1. MySql 最上层是一些客户端和连接服务,包含本地sock通信和大多数基于客户端/服务端工具实现的类似于tcp/ip的通信. 主要完成一些类似于连接处理.授权认证.及相关的安全方案.在该层上引入 ...
- Unity的弱联网Json数据传输
注意事项: 关于dictionary转json的工程中遇到一点问题:要手动添加双引号. 关于json转dictionary:同样需要手动去掉双引号,否则添加到dictionary中的字符串会带有双引号 ...
- openjdk:8u22-jre-alpine在java开发中的NullPointerException错误解决方案
问题描述 ** 在SpringBoot项目中使用了Ureport报表组件, 打包发布部署到docker中启动报错 ** java.lang.NullPointerException at sun.aw ...
- charles(version4.2.1)抓包手机数据
点击菜单栏的Proxy项,选择Proxy Settings. 设置HTTP Proxy的Port. 勾选透明代理Enable transparent HTTP proxying,也可不勾选. 设置代理 ...
- 一段代码分清global和nonlocal
废话不多说,直接代码啊~~~ a=999 b=99999 def test1(): a=888 b=88888 print('a={}'.format(a)) print('b={}'.format( ...
- java读取本机磁盘及遍历磁盘文件
1. 获取本机所有盘符信息 //1. 获取本机盘符 File[] roots = File.listRoots(); for (int i = 0; i < roots.length; i++) ...
- jenkins无法连接到git原因
1.账号密码错误 2.公钥私钥不对应(git上为公钥,jenkins为私钥,私钥比公钥长) 3.公钥私钥文件没有复制到jenkins目录下的.ssh文件中