【问题标题】:SSH connection refused on azure vm天蓝色 vm 上的 SSH 连接被拒绝
【发布时间】:2017-04-07 03:41:43
【问题描述】:

我可以在 Chrome 上渲染虚拟机的公共 ip,但无法通过 SSH 连接它,引发错误:连接到主机 xxx.xxx.xxx.xx 端口 22:连接被拒绝。当我在 Portal 上检查虚拟机时,没有为其分配安全组。这和这个有关系吗?我该如何解决?

【问题讨论】:

  • 您可以从本地 PC 使用端口 22 远程登录 azure vm 吗?
  • 无法在 Windows 10 上使用 telnet。Http 端口工作正常,但 ssh 端口不工作。
  • 无法 telnet azure VM 或无法使用 telnet 此命令?
  • http 在端口 80 上工作,SSH 在端口 22 上工作,您的 VM 在经典 VM 或 Azure 资源 VM 中创建?
  • 开箱即用,您在 Azure 中启动的每个 Linux VM 都会打开一个 ssh 端口。如果您使用 ARM,它将是端口 22。如果您创建了经典 vm,则它是端口 22 或随机端口(如果 cloudapp.net 命名空间中有多个 vm。也许编辑您的问题,提供更多关于配置的端口?

标签: azure ssh virtual-machine


【解决方案1】:

根据你的描述,如果我们想ssh到docker镜像,我们应该在这个镜像上安装SSH,并为这个镜像打开端口,我以运行centos镜像为例:

docker pull centos:centos6
docker run -i -t centos:centos6
yum install openssh-server openssh-client(install ssh)
chkconfig sshd on
passwd(reset root password)
exit
docker commit 332b19ca916c centos/centosssh  (commit this image)

docker run -i -t -d -p 50001:22 centos/centosssh  (NAT for this container)
docker attach containerid  (connect this container)
vi /etc/ssh/sshd_config  (modify sshd config)

change UsePAM to no

service sshd start

然后在 Azure NSG 中打开 50001 端口。

这一次,我们可以使用 SSH 来连接它:

更新:

我使用 CLI 2.0 创建一个带有 docker 扩展的 VM,并将公共 IP 地址更改为 static,并使用命令 sudo docker run -d -p 80:80 nginx 在 VM 上运行容器。然后使用 chrome 测试 nginx,它工作正常,我可以通过 Public IPFQDN SSH 到 Azure VM。 nginx 容器:

jason@MyDockerVM:~$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                         NAMES
61e10ebb6d22        nginx               "nginx -g 'daemon ..."   4 minutes ago       Up 4 minutes        0.0.0.0:80->80/tcp, 443/tcp   kind_leavitt

尝试使用 FQDN ssh 主机:

[c:\~]$ ssh jason@mypublicdns.eastus.cloudapp.azure.com


Host 'mypublicdns.eastus.cloudapp.azure.com' resolved to 52.186.123.151.
Connecting to 52.186.123.151:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.19.0-65-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Fri Apr  7 06:40:06 UTC 2017

  System load:  0.31              Processes:              118
  Usage of /:   5.8% of 28.80GB   Users logged in:        1
  Memory usage: 12%               IP address for eth0:    10.0.0.4
  Swap usage:   0%                IP address for docker0: 172.17.0.1

尝试使用公网IP地址ssh主机:

[c:\~]$ ssh jason@52.186.123.151
Connecting to 52.186.123.151:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.

Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.19.0-65-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

  System information as of Fri Apr  7 06:40:55 UTC 2017

  System load:  0.21              Processes:              119
  Usage of /:   5.8% of 28.80GB   Users logged in:        1
  Memory usage: 12%               IP address for eth0:    10.0.0.4
  Swap usage:   0%                IP address for docker0: 172.17.0.1

【讨论】:

  • 我已经更新了我的答案,它工作正常,请检查它。
  • 如果你运行 docker image 仍然无法 ssh 到 Azure VM,也许我们可以尝试使用 reset ssh configuration,我们可以在这里找到 reset ssh config,选择 VM -->reset password--->在模式下,选择Reset configuration only
  • 所以它正在工作。然后它应该工作。非常感谢杰森
  • @Gene9y - 如果您有新问题,请作为问题提出。没有埋在 cmets 中。
猜你喜欢
  • 2017-01-28
  • 2018-03-14
  • 2017-06-03
  • 1970-01-01
  • 2022-12-22
  • 1970-01-01
  • 2017-08-24
  • 2022-01-07
  • 2013-01-25
相关资源
最近更新 更多