azure - Azure 虚拟机上的 SSH 连接被拒绝

标签 azure ssh virtual-machine

我能够在 Chrome 上呈现虚拟机的公共(public) IP,但无法使用 SSH 连接它,从而引发错误:连接到主机 xxx.xxx.xxx.xx 端口 22:连接被拒绝。当我在Portal上检查虚拟机时,没有为其分配安全组。和这个有关系吗?我该如何修复它?

最佳答案

根据你的描述,如果我们想通过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来连接它:

enter image description here

更新:

我使用 CLI 2.0 创建带有 docker 扩展的虚拟机,并将公共(public) IP 地址更改为静态,并使用命令 sudo docker run -d -p 80:80 nginx 在虚拟机上运行容器。然后使用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 <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="93f9f2e0fcfdd3feeae3e6f1fffaf0f7fde0bdf6f2e0e7e6e0bdf0fffce6f7f2e3e3bdf2e9e6e1f6bdf0fcfe" rel="noreferrer noopener nofollow">[email protected]</a>


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

尝试使用公共(public)IP地址来ssh主机:

[c:\~]$ ssh <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9b3b8aab6b799ecebf7e8e1eff7e8ebeaf7e8ece8" rel="noreferrer noopener nofollow">[email protected]</a>
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

关于azure - Azure 虚拟机上的 SSH 连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43269242/

相关文章:

linux - ubuntu 14.04 无法连接网络并找到 eth0

azure - Azure VM被黑,如何恢复数据?

linux - VM 和本地计算机如何相互连接?

powershell - 如何为 Azure RM 订阅设置默认存储帐户

azure - 通过 Terraform 获取系统分配的托管标识的 Azure 客户端/应用程序 ID

linux - 如何在 Linux 中使用相同目录从我的工作终端打开一个新终端?

linux - bash 脚本中的 wget 只下载部分文件?

java - 使用 Java 访问 Azure 中的 Office 365(sharepoint REST api)

sql-server - 将 Azure Sql 数据库复制到另一台服务器

ios - 如何在 iPhone 上使用 SSH