千家信息网

Windows EC2 Instance 忘记密码如何重置

发表于:2025-12-05 作者:千家信息网编辑
千家信息网最后更新 2025年12月05日,这个问题搞了我2天时间,所以要好好记录一下。对于Windows Server 2012之前和Server 2016之后的处理方式是不一样的,我在误打误撞中,用了2012的方法解决了2016的问题, 因
千家信息网最后更新 2025年12月05日Windows EC2 Instance 忘记密码如何重置

这个问题搞了我2天时间,所以要好好记录一下。对于Windows Server 2012之前和Server 2016之后的处理方式是不一样的,我在误打误撞中,用了2012的方法解决了2016的问题, 因为我不知道忘记密码的EC2是2016版本。
而且Windows的这类问题(忘记key pair和密码)的处理方式比Linux的要复杂。

  1. 关闭该instance, 这个instance tag标记为original-instance

  1. 到Volume处找到该instance的volume,然后Detach

  1. 删除旧Key

  1. 创建一个新的EC2 Instance,tag标记为new-instance

  2. 新Instance要跟有问题的在同一个区域,例如us-east-1a,不然无法加载volume

  1. Launch,然后弄一个跟之前(已经丢失忘记的key)一样的key名字,并下载保存key

以下这步很关键,之前的尝试我都弄错了

  1. 把忘记密码的instance创建Image

  1. 然后在IMAGES -- > AMI中查看进度,需要几分钟时间,完成后点Launch,这个步骤跟新建instance类似,为跟那个新建的instance区分开来,我们把这个instance命名为 image-instance

  1. 创建好后关闭此Instance,然后把image-instance的volume挂载到new-instance上

  1. 登入new-instance,并下载工具:https://s3.amazonaws.com/ec2rescue/windows/EC2Rescue_latest.zip (这个工具仅适用于2016及其后版本的 Windows Server)

另外我之前看文档说可以通过修改Ec2Config service来实现密码修改,后来摸索后才发现这在2012及之前的版本才可以,而我的忘记密码的服务器是2016版本,这也是我奇怪之前没有在路径下看到C:\Program Files\Amazon\Ec2ConfigService这个文件夹了,所以我从2012上copy了一个到这个路径,同时修改了config.xml文件,把EC2Password改为Enabled,不知道跟这个有没关系,权且记录在案。

  1. 然后把这个volume在new-instance上offline,并从Volume上Deattach掉,然后重新挂回image-instance,注意要把Device设为 /dev/sda1,这样才是C盘

  1. 获取image-instance的密码

  1. 导入保存的key文件获取密码,(刚开始的时候是失败的,提示无法获取密码,验证不对,在此我又纠结了几个小时,在这个3个instance之前互相切换挂载,后来就可以获得密码了,不知哪里弄对了)

  1. 然后再关闭这个image-instance, 把这个volume挂载回orignal-instance为C盘,启动,这样就用新的key获取新的密码

参考文档
适用于server 2012及其前版本:https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ResettingAdminPassword_EC2Config.html

适用于server 2016及其后版本:https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/ResettingAdminPassword_EC2Launch.html

这个提到要完全按照步骤来,我也是受这个启发,重新看文档才发现我没有launch image,而是搞了launch new instance,这点很关键。https://stackoverflow.com/questions/50686939/resetting-administrator-password-for-aws-ec2-windows-server-2012-instance

后来收到AWS Support发来的邮件支持信息,不过我的问题已经自己解决,所以没有使用他们的方法,记录如下:
对于server 2016

  1. In the Amazon IAM Console (https://console.aws.amazon.com/iam/), in the navigation pane, choose Roles, Create new role.

  2. Choose Amazon EC2 Role for Simple Systems Manager, and then choose Select.

  3. Under Policy Name, check AmazonEC2RoleforSSM, Next Step, enter a Role name that is meaningful to you and choose Create Role.

  4. Open the Amazon EC2 console, https://console.aws.amazon.com/ec2/ and choose the appropriate region.

  5. Select the affected instance, choose Actions, Instance Settings, Attach/Replace IAM role. This would attach the IAM role you just created to your instance.

  6. From EC2 console select, "Run Command" and "Run a command" option.

  7. Select "AWS-RunPowershellScript" from Command document

  8. In Select Targets, Select the instance you want to reset password for. Should the instance not be populated in the list, please wait for some time so that the changes can be propagated.

  9. Under Commands, run the following command while replacing "new_password" with your password.

    net user Administrator new_password

  10. Click Run in the lower right, leaving all the settings at default.

Following the successful completion of the run command, you should now be able to log in with that local administrator password you just keyed in under step 9. Once you've regained access to the instance, change the password to a more permanent value by running the command from step 9 again in command prompt of the instance.

Another procedure you can follow to reset the password on the instance is to use the AWSSupport-ResetAccess Automation document from the Systems Manager console. This document is useful if you have lost your EC2 key pair and want to create a password-enabled AMI from your EC2 instance, so you can launch a new instance with an existing key pair. To perform this, you can follow the steps given on the link under the section headed "Systems Manager Automation AWSSupport-ResetAccess (Offline Method)":

[+] https://aws.amazon.com/premiumsupport/knowledge-center/reset-admin-password/

密码 版本 问题 文件 文档 关键 工具 方式 方法 标记 步骤 路径 处理 不对 复杂 对了 没关系 误打误撞 下载工具 信息 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 英文版2012服务器管理 我的世界网易版服务器导出地图 部队网络安全授课课件 网络安全poc验证 计算机网络技术网络管理方向 数据库原理及应用第二版课后实验 数据库中一个关系代表一个 黑魂服务器 全国网络安全管理中心 网络安全成语有哪些 合肥隆天互联网科技有限公司 在线检查网络安全 网络安全方针政策知识 杭州网络技术服务费用 用代理服务器访问国外网站违法吗 上海 外高桥 软件开发公司 宝山区媒体数据库服务价钱 中国邮政数据库官网 b次元显示无法连接服务器 玛雅视频软件开发 苍南现代化刀片服务器不二之选 手机app查询数据库设计 海湾北代表处网络安全大会 如何搭建自己的私有云服务器 四川服务器虚拟化操作云服务器 网络安全三法一例 计算机信息网络安全法是 服务器安全设置下载文件 张家港帷幄网络技术 肇庆西餐桌上点餐软件开发
0