Ubuntu 储户非常感谢。哇!只有这个解决方案对我有效。其他答案主要是关于将实例修复为以前的状态(在启用ufw之前)。尽管启用了ufw,但这是唯一一个关于通过ssh连接的协议。谢谢。@ADB你能解释一下这三行代码的作用吗?你们是怎么想出这种解决方案的?需要什么样的经验

Ubuntu 储户非常感谢。哇!只有这个解决方案对我有效。其他答案主要是关于将实例修复为以前的状态(在启用ufw之前)。尽管启用了ufw,但这是唯一一个关于通过ssh连接的协议。谢谢。@ADB你能解释一下这三行代码的作用吗?你们是怎么想出这种解决方案的?需要什么样的经验,ubuntu,amazon-ec2,ufw,Ubuntu,Amazon Ec2,Ufw,储户非常感谢。哇!只有这个解决方案对我有效。其他答案主要是关于将实例修复为以前的状态(在启用ufw之前)。尽管启用了ufw,但这是唯一一个关于通过ssh连接的协议。谢谢。@ADB你能解释一下这三行代码的作用吗?你们是怎么想出这种解决方案的?需要什么样的经验?这是为我做的!Ubuntu 18.04.2,ec2 t2.micro。互联网研究技能,以及大量的AWS白皮书阅读都将大有帮助。我只是觉得自己像个黑客!天啊!非常感谢。 sudo ufw allow 27017 cd ~ mkdir lnx1


储户非常感谢。哇!只有这个解决方案对我有效。其他答案主要是关于将实例修复为以前的状态(在启用ufw之前)。尽管启用了ufw,但这是唯一一个关于通过ssh连接的协议。谢谢。@ADB你能解释一下这三行代码的作用吗?你们是怎么想出这种解决方案的?需要什么样的经验?这是为我做的!Ubuntu 18.04.2,ec2 t2.micro。互联网研究技能,以及大量的AWS白皮书阅读都将大有帮助。我只是觉得自己像个黑客!天啊!非常感谢。
sudo ufw allow 27017
cd ~
mkdir lnx1
sudo mount /dev/xvdf ./lnx1
cd lnx1
sudo vim ufw.conf
sudo umount ./lnx1/
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
--//
  $ sudo mount /dev/xvdf1 /mnt
  $ cd /mnt/etc/ufw
  $ sudo vim ufw.conf
  $ sudo cat ufw.conf 
  $ cd ~
  $ sudo umount /mnt

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
--//
#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"
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
--//
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
--//