在Amazon 22上的端口上的Amazon EC2实例上运行ssh [英] Running ssh on Amazon EC2 instance on port other than 22

查看:1582
本文介绍了在Amazon 22上的端口上的Amazon EC2实例上运行ssh的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法通过ssh访问Amazon EC2实例,因为我在防火墙后面。
所以,我想在22以外的端口运行ssh,比如80或443。

I am not able to access Amazon EC2 instance via ssh as i am behind a firewall. So, i thought of running ssh on port other than 22, like 80 or 443.

我试过通过Web管理控制台启动Amazon EC2实例,用户数据:

I tried starting Amazon EC2 instance via Web Management Console with following 'user data':

#!/bin/bash -ex
perl -pi -e 's/^#?Port 22$/Port 80/' /etc/ssh/sshd_config
service sshd restart || service ssh restart

这个想法是上面的脚本将在实例启动时执行,并从端口22切换ssh到端口80.(参考: http://alestic.com/2010/12/ec2-ssh-port -80

The idea being that the above script would execute on instance startup and switch ssh from port 22 to port 80. (Ref: http://alestic.com/2010/12/ec2-ssh-port-80)

但是ssh在端口80上仍然无法访问。
显然用户数据脚本在启动时没有执行?

But ssh is still not accessible on port 80. Apparently 'user data' script is not being executed on start up?

我只能通过Web管理控制台启动停止实例,而不是从命令行(位于防火墙后)

I can 'only' start stop instances via Web Management Console, not from command-line (being behind firewall)

任何想法?

推荐答案

亚马逊防火墙阻止所有22端口。您首先必须启用端口80/443 / any。

The amazon firewall blocks all ports other than 22. You first have to enable port 80/443/whatever.

HOWTO:
转到安全组 - >单击您为实例选择的组,然后在入站选项卡上。

HOWTO: Go to "security groups" -> click on the group you chose for your instance, then on the "Inbound" tab.

您可以添加您的端口。

编辑:如果偶然您还安装了apache或其他网络服务器,将使用端口80,并且不能由sshd使用。我不知道您的服务器上安装了哪个操作系统,但是可能已经包含了一些网络服务器?

If by chance you also installed apache or some other webserver, port 80 will be used and cannot be used by sshd. I do not know which operating system is installed on your server, but maybe some webserver is already included?

这篇关于在Amazon 22上的端口上的Amazon EC2实例上运行ssh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆