我有一个Ubuntu的EC2示例。我使用了sudo ufw enable,之后只允许mongodb端口
sudo ufw enable
sudo ufw allow 27017
当ssh连接中断时,我无法重新连接
ergxz8rk1#
#更新
最简单的方法是更新示例的用户数据
Instance Settings
Edit User Data
Actions
如果您仍在旧版AWS控制台上,请选择示例,然后转到Actions-〉Instance Settings-〉View/Change User Data把这个贴上
View/Change User Data
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 ufw disable iptables -L iptables -F --//
源代码here
#旧答案
使用另一个示例分离并修复问题示例的卷
sudo lsblk
$ sudo mount /dev/xvdf1 /mnt $ cd /mnt/etc/ufw
ufw
$ sudo vim ufw.conf
ENABLED=yes
ENABLED=no
$ sudo cat ufw.conf
$ cd ~ $ sudo umount /mnt
来源:here
crcmnpdw2#
我有同样的问题,并发现这个步骤的作品:1-停止示例2-转到Instance Settings-〉View/Change user Data
View/Change user Data
更新:新AWS控制台UI上的路径
右键单击Stopped示例-〉Instance Settings-〉Edit User Data3-将其粘贴到选项Modify user data as text上并保存
Stopped
Modify user data as text
4-启动示例希望它对你有用!
lrpiutwd3#
注意:较新的Linux内核可能会在内部将您的设备重命名为/dev/xvdf到/dev/xvdp,即使输入的设备名称是/dev/sdf到/dev/sdp。
cd ~ mkdir lnx1 sudo mount /dev/xvdf ./lnx1
cd lnx1 sudo vim ufw.conf
现在找到ENABLED=yes并将其更改为ENABLED= no。
请务必先卸载卷:
sudo umount ./lnx1/
你好!2!3你做得很好。
b5lpy0ml4#
其他方法对我不起作用。我的EC2示例是基于Bitnami映像的。由于市场锁定,将卷附加到另一个示例不起作用。因此,请停止问题示例,并将此脚本粘贴到instanceSettings〉view-change user data中。
此方法不需要分离卷,因此与其他方法相比更加简单。
在粘贴之前必须停止示例,在粘贴之后启动你的示例,你应该能够ssh。
nhaq1z215#
我知道这是一个老问题,但我使用bootcmd在“查看/更改用户数据”中添加了一个命令,从而修复了我的问题我首先停止了示例然后我在用户数据中添加了这个
bootcmd
# cloud-config bootcmd: - cloud-init-per always fix_broken_ufw_1 sh -xc "/usr/sbin/service ufw stop >> /var/tmp/svc_$INSTANCE_ID 2>&1 || true" - cloud-init-per always fix_broken_ufw_2 sh -xc "/usr/sbin/ufw disable>> /var/tmp/ufw_$INSTANCE_ID 2>&1 || true"
#注意:我的示例是Ubuntu
qcuzuvrc6#
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 set -x USERNAME="ubuntu" ls -Al ls -Al /home ls -Al /home/${USERNAME} ls -Al /home/${USERNAME}/.ssh sudo cat /home/${USERNAME}/.ssh/authorized_keys ls -Al /etc/ssh ls -ld /etc/ssh sudo grep -vE '^$|^#' /etc/hosts.* sudo sed -i -e 's/^\([^#].*\)/# \1/g' /etc/hosts.deny sudo sed -i -e 's/^\([^#].*\)/# \1/g' /etc/hosts.allow sudo grep -vE '^$|^#' /etc/hosts.* sed '/^$\|^#/d' /etc/ssh/sshd_config chown -v root:root /home chmod -v 755 /home chown -v ${USERNAME}:${USERNAME} /home/${USERNAME} -R chmod -v 700 /home/${USERNAME} chmod -v 700 /home/${USERNAME}/.ssh chmod -v 600 /home/${USERNAME}/.ssh/authorized_keys sudo tail /var/log/auth.log sudo ufw status numbered sudo ufw disable sudo iptables -F sudo service iptables stop sudo service sshd restart sudo service sshd status -l --//
6条答案
按热度按时间ergxz8rk1#
#更新
最简单的方法是更新示例的用户数据
Instance Settings
-〉Edit User Data
或选择示例并转到Actions
-〉Instance Settings
-〉Edit User Data
如果您仍在旧版AWS控制台上,请选择示例,然后转到
Actions
-〉Instance Settings
-〉View/Change User Data
把这个贴上
源代码here
#旧答案
使用另一个示例分离并修复问题示例的卷
sudo lsblk
以显示连接的卷,并确认问题卷的名称。ufw
配置文件ENABLED=yes
更改为ENABLED=no
ENABLED=yes
已更改为ENABLED=no
来源:here
crcmnpdw2#
我有同样的问题,并发现这个步骤的作品:
1-停止示例
2-转到
Instance Settings
-〉View/Change user Data
更新:新AWS控制台UI上的路径
右键单击
Stopped
示例-〉Instance Settings
-〉Edit User Data
3-将其粘贴到选项
Modify user data as text
上并保存4-启动示例
希望它对你有用!
lrpiutwd3#
注意:较新的Linux内核可能会在内部将您的设备重命名为/dev/xvdf到/dev/xvdp,即使输入的设备名称是/dev/sdf到/dev/sdp。
现在找到ENABLED=yes并将其更改为ENABLED= no。
请务必先卸载卷:
你好!2!3你做得很好。
b5lpy0ml4#
其他方法对我不起作用。我的EC2示例是基于Bitnami映像的。由于市场锁定,将卷附加到另一个示例不起作用。
因此,请停止问题示例,并将此脚本粘贴到instanceSettings〉view-change user data中。
此方法不需要分离卷,因此与其他方法相比更加简单。
在粘贴之前必须停止示例,在粘贴之后启动你的示例,你应该能够ssh。
nhaq1z215#
我知道这是一个老问题,但我使用
bootcmd
在“查看/更改用户数据”中添加了一个命令,从而修复了我的问题我首先停止了示例
然后我在用户数据中添加了这个
#注意:我的示例是Ubuntu
qcuzuvrc6#
下面是用户数据脚本的 * 扩展版本 *: