首页 > 其他分享 >使用EC2 Userdata为丢失密钥的EC2更换密码

使用EC2 Userdata为丢失密钥的EC2更换密码

时间:2023-02-26 16:02:38浏览次数:35  
标签:Userdata 1.0 Content Version MIME EC2 config cloud 密钥

EC2实例-使用Shell 脚本和 cloud-init 指令组合使用 免密钥登录

Content-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
 
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
 
#cloud-config
cloud_final_modules:
- [scripts-user, always]
 
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
 
#!/bin/bash
echo "root:XXXXX" | chpasswd
sed -i "s/PasswordAuthentication no/PasswordAuthentication yes/" /etc/ssh/sshd_config
sed -i "s/PermitRootLogin forced-commands-only/PermitRootLogin yes/" /etc/ssh/sshd_config
service sshd restart
--//

标签:Userdata,1.0,Content,Version,MIME,EC2,config,cloud,密钥
From: https://blog.51cto.com/u_14169716/6086625

相关文章