0
点赞
收藏
分享

微信扫一扫

无法使用 SSH 连接Azure Linux 虚拟机

本文提供了因为 /var/empty/sshd 文件不在根目录且不可进行组或全局可写导致SSH 连接失败问题的解决方案。

​问题现象​

​无法使用安全外壳 (SSH) 连接来连接 Linux 虚拟机 (VM)。发生此问题时,您可能会收到以下有关 /var/empty/sshd 文件的错误消息,具体取决于 Linux 发行版。

SuSE:

/var/empty must be owned by root and not group or world-writable.

startproc: exit status of parent of /usr/sbin/sshd: 255

Failed

Centos:

Starting sshd: /var/empty/sshd must be owned by root and not group or world-writable.

[FAILED]

原因

如果 /var/empty/sshd 文件不归根目录所有,并且不可进行组写入或全局写入,则可能会出现此问题。

解决方案

若要在无法访问 SSH 时更改 Linux 文件的权限,在 Azure 门户 中打开虚拟机的"属性"窗口,检查代理状态。

无法使用 SSH 连接Azure Linux 虚拟机_linux

如果代理已启用,请按照以下步骤更改权限:

  1. 将以下脚本复制到本地计算机,然后将该文件重命名为 update_perms.sh

#!/bin/bash

#Script to change permissions on a file

###################################################

param=$1

chmod 755 /var/empty/sshd;chown root:root /var/empty/sshd;service sshd restart

  1. 转到 Azure 门户,找到 VM 设置,然后选择扩展 >,为Linux 创建 > 添加自定义 > 脚本

无法使用 SSH 连接Azure Linux 虚拟机_解决方案_02


无法使用 SSH 连接Azure Linux 虚拟机_根目录_03

无法使用 SSH 连接Azure Linux 虚拟机_解决方案_04

  1. 在 "脚本文件"中,上载 update_perms.sh 文件,然后单击"确定 "。

无法使用 SSH 连接Azure Linux 虚拟机_根目录_05

无法使用 SSH 连接Azure Linux 虚拟机_解决方案_06

  1. 将脚本推送到 VM 后 ,STATUS 值应为 Success

无法使用 SSH 连接Azure Linux 虚拟机_解决方案_07

  1. the update_perms.sh sample script changes the permissions on the /var/empty/sshd file from 777 to 755 and sets the owner and group to root:root. 等待脚本运行。 这可能需要几分钟。 Linux 代理接收请求,然后提交到正确的扩展。 如果可以使用 SSH 连接连接到 VM,并且希望查看运行 update_params.sh 脚本时发生的情况,请检查目录中的 extension.log /var/log/azure/Microsoft.OSTCExtensions.CustomScriptForLinux/<version> 文件。


举报

相关推荐

0 条评论