0
点赞
收藏
分享

微信扫一扫

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

楠蛮鬼影 2023-02-26 阅读 132

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
--//
举报

相关推荐

0 条评论