Xshell: Unable to login to virtual VM using ssh

Abstract: Resolve Xshell SSH login failures to virtual machines by fixing VirtualBox network adapter settings, enabling the guest SSH service, and adjusting firewall rules.

Created: 2026-09-17 by

SSH login failures in Xshell with virtual machines typically stem from misconfigured port forwarding, incorrect IP addresses, or restrictive firewall rules. By verifying the VirtualBox network adapter settings, ensuring the guest OS SSH service is active, and confirming that Xshell connects to the correct host key, you can resolve most connection issues without altering core system configurations.

Verify Network Adapter Configuration

The most common reason for SSH connectivity failure between a host machine and a virtual machine (VM) is an improper network adapter setup in VirtualBox. If the VM is set to "NAT" mode by default, it receives an internal IP address that is not directly accessible from the host’s external network interface. While NAT allows the VM to access the internet, it does not allow incoming connections from the host unless specific port forwarding rules are established. To check if this is your issue, open the VirtualBox Manager and select your VM. Navigate to Settings > Network. If the Adapter 1 tab shows "Attached to: NAT," you must either switch to "Bridged Adapter" or configure Port Forwarding. Bridged Adapter mode makes the VM appear as a distinct device on your local network, allowing it to obtain its own IP address via DHCP from your router. This is often the easiest solution for direct SSH access. If you prefer to keep NAT mode for security isolation, you need to add a port forwarding rule. Go to Settings > Network > Advanced > Port Forwarding. Add a new rule where the Host IP is 127.0.0.1, Host Port is 2222 (or another available port), Guest IP is left blank, and Guest Port is 22. After saving, you would connect to localhost:2222 in Xshell instead of the standard port 22. However, switching to Bridged Adapter is generally more straightforward for development environments.

Confirm Guest OS SSH Service Status

Even with perfect network configuration, the SSH daemon inside the guest operating system must be running and listening for connections. In many minimal Linux distributions used for VMs, the OpenSSH server package is not installed by default. You can verify this by opening a terminal within the VM itself. Run the command systemctl status sshd or service ssh status depending on your init system. If the service is inactive or not found, you will need to install and enable it. For Debian-based systems like Ubuntu, execute:
sudo apt update
sudo apt install openssh-server
sudo systemctl enable ssh
sudo systemctl start ssh
For Red Hat-based systems like CentOS or Fedora, use:
sudo dnf install openssh-server
sudo systemctl enable sshd
sudo systemctl start sshd
Once installed, ensure the service is enabled to start on boot. If the service is running but still unreachable, check the listening ports using netstat -tulpn | grep :22 or ss -tulpn | grep :22. The output should show sshd listening on 0.0.0.0:22 or [::]:22. If it only listens on 127.0.0.1, the SSH configuration file (/etc/ssh/sshd_config) may have ListenAddress restricted to localhost. Change this to 0.0.0.0 and restart the service.

Check Firewall Rules

Firewalls on the guest OS often block incoming SSH connections even when the network path is valid. Most modern Linux distributions come with ufw (Uncomplicated Firewall) or firewalld enabled by default. If these tools are active, they may drop packets destined for port 22. For ufw, check the status with sudo ufw status. If it is active, allow SSH traffic by running sudo ufw allow ssh or sudo ufw allow 22/tcp. Then reload the rules with sudo ufw reload. For firewalld, use the following commands to permit SSH permanently:
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --reload
If you are unsure which firewall is managing your rules, you can temporarily disable the firewall to test connectivity. Run sudo ufw disable or sudo systemctl stop firewalld. If SSH works after disabling the firewall, re-enable it and properly configure the allowed services rather than leaving it off. Remember that disabling the firewall exposes your VM to potential network threats, so always restore protection immediately after testing.

Validate Xshell Connection Parameters

With the network and guest OS configured correctly, the next step is to ensure Xshell is sending the request correctly. Open Xshell and create a new session or edit your existing one. In the Host field, enter the IP address of the VM. If you are using Bridged Adapter, this is the IP assigned by your router. If you are using NAT with port forwarding, enter 127.0.0.1 and change the Port number to the forwarded port (e.g., 2222). Click OK to save, then double-click the session to connect. If you receive a "Connection Refused" error, the target port is not open or the service is down. If you get a "Host Key Verification Failed" warning, it means the SSH host key has changed, possibly due to a fresh reinstall of the guest OS. Accept the new key to proceed. Additionally, verify that the username entered in Xshell matches a valid user account on the guest VM. Incorrect credentials will result in an authentication failure rather than a connection timeout. If you are using public key authentication, ensure the private key selected in Xshell corresponds to the public key placed in the guest's ~/.ssh/authorized_keys file.

Related Resources

If you encounter persistent networking issues, consider reviewing Troubleshooting Vagrantfile Errors for deeper infrastructure debugging techniques. For secure file transfers once connected, see How to sync files overnight from a remote server?.

Frequently Asked Questions

Why does Xshell say "Connection Timed Out"?

This usually indicates that packets are being dropped by a firewall or that the route to the VM is invalid. Check both the host and guest firewalls to ensure port 22 is open. Also, verify that the VM's IP address has not changed due to DHCP lease expiration.

Can I use PuTTY instead of Xshell for this connection?

Yes, PuTTY uses the same SSH protocol and will work identically if the network and guest OS configurations are correct. Xshell offers additional features like tabbed sessions and script automation, but the underlying connection mechanics remain the same.

What if my VM is behind a NAT gateway?

If the VM is strictly behind NAT without port forwarding, you cannot initiate inbound SSH connections directly. You must either switch the network adapter to Bridged mode or configure explicit port forwarding rules in the VirtualBox settings to map a host port to the guest's port 22.

How do I reset the root password if I am locked out?

You can reboot the VM into recovery mode or single-user mode from the VirtualBox console. Once booted, remount the root filesystem as read-write and use the passwd command to change the password. This requires physical or console access to the VM manager, not SSH.

Is it safe to run SSH on a virtual machine?

Yes, SSH is encrypted and widely considered safe for remote administration. However, ensure you disable password authentication in favor of key-based authentication and restrict root login in /etc/ssh/sshd_config to minimize the attack surface against brute-force attempts.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More