服务器又中毒了,root密码还被篡改了、忘记root密码、免密码连接,私钥连接

您所在的位置:网站首页 gg修改器修改了怎么会变回来 服务器又中毒了,root密码还被篡改了、忘记root密码、免密码连接,私钥连接

服务器又中毒了,root密码还被篡改了、忘记root密码、免密码连接,私钥连接

2024-07-10 21:20| 来源: 网络整理| 查看: 265

服务器又中毒了,root密码还被篡改了

发现ssh 都连不上,我的好几台虚拟机的密码都很简单,最近经常中毒,我又基本不开防火墙的,可能是什么端口被入侵了

密码被改了还有一种连接方式,使用私钥连接

条件: 服务器有其他入口,可以修改 /root/.ssh/authorized_keys 的内容 这样就能用私钥连上,就能重新修改root密码了,不需要使用grub方式来修改密码

说明

本机= 客户端: 要连上服务器的机子 服务器: linux 主机,

一、在客户端生成公私钥

打开cmd:

ssh-keygen -t rsa -C [email protected]

然后一路回车 这是我执行的结果

resabdeMacBook-Pro:~ resab$ ssh-keygen -t rsa -C [email protected] Generating public/private rsa key pair. Enter file in which to save the key (/Users/resab/.ssh/id_rsa): h5-happygame Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in h5-happygame. Your public key has been saved in h5-happygame.pub. The key fingerprint is: SHA256:kSo2YSDQW90gDlk5CAAKsq/EFUluC0DEO37Ni4HksSY [email protected] The key's randomart image is: +---[RSA 2048]----+ |^=+*+o.o | |=+===.. .. | |o..*+. o | |.*=... . . | |+o*.* . S | |EB + = | |+ . o . | | . . | | | +----[SHA256]-----+ resabdeMacBook-Pro:~ resab$ 二、进入用户目录查看公私钥 1.进入 ~/.ssh 目录 [root@localhost .ssh]# pwd /root/.ssh [root@localhost .ssh]# tree . ├── authorized_keys #存放他机公钥 ├── id_rsa # 私钥 放在本机 ├── id_rsa.pub # 公钥 放到服务器 └── known_hosts # 已经识别的主机名 0 directories, 4 files [root@localhost .ssh]# 三、 把本机id_rsa.pub的文本内容复制,加入到服务器的authorized_keys文件里(最重要)

如果服务器没有/root/.ssh/authorized_keys这个文件,那就新建一个,粘贴进去

如果服务器已经有了这个文件,则把本机~/.ssh/id_rsa.pub的内容加到服务器的/root/.ssh/authorized_keys的最后面。

操作手段

看看服务器有没有放行什么有用的服务,我的服务器开了宝塔,可以直接编辑 /root/.ssh/authorized_keys 在这里插入图片描述 如果ftp 刚好直接操作 /root文件 夹,ftp应该也行

连接

1.xshell 连接

在这里插入图片描述 或者 2. cmd 命令行连接 ssh -i 私钥位置 root@服务器ip 如: ssh -i ~.ssh\id_rsa [email protected]

C:\Users\14210>ssh -i C:\Users\14210\.ssh\id_rsa [email protected] Last login: Tue Dec 1 11:26:30 2020 from 192.168.199.249 [root@localhost ~]# 四、centos修改密码

passwd 然后直接输入新密码,

Connecting to 192.168.199.93:22... Connection established. To escape to local shell, press Ctrl+Alt+]. WARNING! The remote SSH server rejected X11 forwarding request. Last failed login: Tue Dec 1 10:39:09 CST 2020 from 192.168.199.249 on ssh:notty There were 8 failed login attempts since the last successful login. Last login: Tue Dec 1 07:29:51 2020 from 192.168.199.94 [root@localhost ~]# # 连接成功 [root@localhost ~]# passwd Changing password for user root. New password: BAD PASSWORD: The password contains the user name in some form Retype new password: passwd: all authentication tokens updated successfully. 总结: root密码忘记,改了就忘记了,中毒被改了,不能登录

如果服务器有后门,有漏洞, 可以修改 /root/.ssh/authorized_keys 的内容 就可以被远程登录 在这里,我的后门就是宝塔面板,如果没有只能用grub 改启动参数来改了



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3