How to SSH from ESXi into a VM | How to Retrieve Files from a VM via ESXi

怎么从ESXi SSH去虚拟机 | 怎么从ESXi获取一个VM的内部文件

In this post, we explore how to access a virtual machine hosted on an ESXi server using SSH—that is, how to access and extract files from inside a VM directly via the ESXi host.


The Scenario

Sometimes, while managing VMware environments, you may encounter a situation where a VM’s network configuration appears normal but, due to certain network or system issues, the virtual machine suddenly becomes unreachable from external sources. In such cases:

  • The VM fails to respond to ping requests from outside, and it cannot reach external networks (including the gateway).
  • The only system that can still access the VM is the ESXi host itself.

When you need to extract files or logs from the VM under these circumstances, you must work through the ESXi host.


Prerequisites for Retrieving VM Files via ESXi

Before you begin, ensure the following:

  1. Connectivity:
    The ESXi host must be able to communicate with the VM (i.e., the VM should be pingable from ESXi).
  2. SSH on ESXi:
    SSH must be enabled on the ESXi host. (Make sure the ESX firewall allows SSH client access.)
  3. VM Network Settings:
    The VM’s internal network and firewall settings should permit SSH connections, and the SSH service must be running.

For example, if your VM runs Ubuntu Linux, verify that its firewall and SSH daemon are configured correctly by running:

sudo ufw status
sudo systemctl status sshd

You should see that the firewall is disabled and the SSH daemon (sshd) is active.

Additionally, log in to the ESXi host via SSH and review the options for the ssh and scp commands to familiarize yourself with the available parameters.


Copying a File from the VM via ESXi

Once the prerequisites are met, you can retrieve a file from the VM using the following command on the ESXi host. (Note: You must know the complete path of the file within the VM.)

scp <VM_username>@<VM_IP_address>:/full/path/to/file /local_ESXi_directory

For example:

scp root@10.x.x.x:/tmp/test.txt /vmfs/volumes/xxxx

Note:
If you encounter an error such as:

ssh: connect to host 10.x.x.x port 22: Connection timed out

then you need to enable the SSH client on the ESXi firewall by executing:

esxcli network firewall ruleset set --enabled=true --ruleset-id=sshClient

After enabling this setting, run the scp command again. Once you enter the VM’s password, the file (e.g., /tmp/test.txt) should be successfully copied to the designated directory on the ESXi host.


Summary of Practical Tips

  • Accessing VM Files via ESXi:
    When external network access is unavailable, use SSH from the ESXi host to access the VM’s files.
  • Copying Files to ESXi:
    Utilize the scp command to transfer files from the VM to the ESXi host.
  • Ensuring Access Despite External Issues:
    Enable the SSH client on ESXi so that even if external connectivity fails, you can still access internal VM data.

Mastering the technique of extracting files from a VM via ESXi not only enhances your troubleshooting efficiency but also ensures that critical data remains accessible and secure during routine operations.

图书推介 - 京东自营

24小时热门

还有更多VMware问题?

免费试下我们的VMware技术助理(已接Deepseek)!即时解答VM难题 → 🤖VM技术助理


########

扫码加入VM资源共享交流微信群(请备注加群

需要协助?或者只是想技术交流一下,直接联系我们!

推荐更多

vCenter虚拟机硬盘显示0GB | VMware虚拟机硬盘显示0GB
how-to

vCenter Virtual Machine Disk Shows 0GB

Encountering a situation where all virtual machine disks in vCenter show 0GB and options are greyed out? This issue often stems from an SSL certificate mismatch. In this guide, we walk you through diagnosing the problem and fixing it using VMware’s lsdocter script.

ESXi 9.0只支持UEFI启动,不再支持传统BIOS?
what-is

ESXi 9.0 Only Supports UEFI Boot – Is Legacy BIOS on Its Way Out?

VMware is moving towards a UEFI-only boot model, and ESXi 9.0 may completely drop legacy BIOS support. A recent blog by VMware architect William Lam and official VMware KB articles reinforce this shift. Administrators should assess their ESXi hosts and plan for a transition to UEFI to ensure future compatibility and security.

//madurird.com/4/9119499