Connecting Ubuntu 20.04 to Hyper-V using OpenSSH, not vsftpd
Abstract: Configure OpenSSH on Ubuntu 20.04 to enable secure remote management and file transfer from a Hyper-V host without using FTP.
2026-09-20
Created: 2026-09-20 by
UserComp.com Editors
Setting up an OpenSSH connection between Ubuntu 20.04 and Microsoft Hyper-V provides a secure, encrypted alternative to legacy FTP protocols like vsftpd. This method allows you to manage your virtual machine via command line with strong authentication and data integrity. By configuring the SSH daemon correctly on the guest OS and adjusting network settings in Hyper-V Manager, you can establish a reliable remote access channel that supports file transfers, remote administration, and automated scripting tasks without exposing sensitive credentials over unencrypted networks.
Prerequisites for Secure Remote Access
Before configuring the software components, ensure that both the host machine running Windows Hyper-V and the Ubuntu 20.04 virtual machine are properly initialized. The Ubuntu VM must have a static IP address assigned within its internal network or through the DHCP server of your router if bridged. A static IP prevents connection drops caused by lease renewals changing the address dynamically. Additionally, verify that the OpenSSH server package is installed on the Ubuntu instance. If it is missing, install it using sudo apt update && sudo apt install openssh-server. This package includes the sshd daemon required to listen for incoming connections.
You should also confirm that the Hyper-V virtual switch is configured appropriately. For most development and testing scenarios, an Internal Virtual Switch or a Private Virtual Switch works well because it isolates the VM from external networks, reducing attack surfaces. However, if you need internet access from the VM, a External Virtual Switch bound to your physical network adapter is necessary. Ensure that the firewall on the Windows host allows inbound traffic on port 22, which is the default SSH port. You can create an inbound rule in Windows Defender Firewall to permit TCP traffic on this port specifically for the Hyper-V management process.
Configuring the SSH Daemon on Ubuntu
The core of the setup involves modifying the configuration file for the SSH daemon located at /etc/ssh/sshd_config. Open this file with a text editor such as nano or vim using sudo privileges. First, locate the Port directive and ensure it is set to 22 unless you have a specific reason to use a non-standard port. Changing the port adds a minor layer of obscurity but does not replace proper security measures. Next, find the PermitRootLogin setting. It is highly recommended to set this to no or prohibit-password to prevent direct root access via password, forcing you to log in as a standard user and escalate privileges when needed.
Disable password authentication entirely by setting PasswordAuthentication no. This forces the use of key-based authentication, which is significantly more secure against brute-force attacks. Generate an SSH key pair on your local machine if you do not have one already, using ssh-keygen -t ed25519. Copy the public key to the Ubuntu VM using ssh-copy-id user@ip_address. This command appends your public key to the ~/.ssh/authorized_keys file on the remote server. After making these changes, restart the SSH service with sudo systemctl restart sshd to apply the new configuration. Test the connection from your local machine to ensure you can log in using your key without being prompted for a password.
Establishing the Connection from Hyper-V Host
Once the SSH server is configured and secured, you can initiate the connection from your Windows host. Open PowerShell or Command Prompt and type ssh username@ubuntu_ip_address. Replace username with your actual Ubuntu username and ubuntu_ip_address with the static IP you assigned earlier. If the connection succeeds, you will see a welcome message and a shell prompt, indicating that you are now remotely controlling the Ubuntu 20.04 instance. This method is vastly superior to using vsftpd because SSH encrypts all transmitted data, including commands and file contents, protecting them from eavesdropping on the local network.
For advanced usage, consider enabling X11 forwarding if you need to run graphical applications from the Ubuntu VM on your Windows desktop. Add X11Forwarding yes to the sshd_config file and restart the service. On the Windows side, you will need an X server like VcXsrv installed. Then, connect using ssh -X username@ip_address. This allows you to launch GUI tools remotely while keeping the processing power on the VM. This approach integrates seamlessly with other Linux administration tasks, allowing you to manage services, edit configurations, and monitor system logs directly from a single terminal window.
Troubleshooting Common Issues
If you encounter connection timeouts, check the virtual switch settings in Hyper-V Manager. Ensure that the VM is connected to the correct virtual network adapter. Sometimes, disabling and re-enabling the network adapter inside the Ubuntu guest OS can resolve temporary connectivity glitches. Use sudo ip link set eth0 down followed by sudo ip link set eth0 up to reset the interface. If you receive permission denied errors, verify that your private key has the correct permissions. On Linux hosts, keys must be readable only by the owner (chmod 600 ~/.ssh/id_ed25519). On Windows, ensure that PuTTY or OpenSSH client is pointing to the correct key file.
Another common issue arises when the SSH service fails to start after configuration changes. Check the status of the service using sudo systemctl status sshd. Look for any error messages related to syntax errors in the sshd_config file. You can test the configuration validity before restarting by running sudo sshd -t. If this command returns no output, the configuration is syntactically correct. If it reports errors, fix them in the config file and try again. For persistent issues, consult the system logs at /var/log/auth.log for detailed authentication failure reasons.
Enhancing Security and Performance
To further harden your SSH connection, consider implementing fail2ban. This tool monitors log files for repeated failed login attempts and temporarily bans the offending IP addresses. Install it with sudo apt install fail2ban and enable it to protect your SSH service automatically. Additionally, disable unused authentication methods in sshd_config by setting KerberosAuthentication no and GSSAPIAuthentication no. These features can cause delays during login if they are not required in your environment. Disabling them speeds up the connection process and reduces the attack surface.
Regularly updating the OpenSSH package is crucial for maintaining security. Run sudo apt upgrade openssh-server periodically to patch known vulnerabilities. Keep your Windows host updated as well to ensure compatibility with the latest SSH protocols. While vsftpd might seem simpler for basic file transfers, it lacks the robust encryption and flexible control provided by SSH. By sticking with OpenSSH, you gain a versatile tool that handles everything from simple file copies to complex remote deployments securely.
Frequently Asked Questions
Can I use SSH to transfer files instead of FTP?
Yes, you can use SCP or SFTP clients to transfer files securely over the SSH connection. Commands like scp local_file user@ip:/remote_path allow you to copy files without installing additional server software. This method is faster and more secure than traditional FTP because it uses the existing encrypted tunnel.
Why is my SSH connection slow on Ubuntu 20.04?
Slow connections are often caused by GSSAPI authentication attempts timing out. Setting GSSAPIAuthentication no in sshd_config usually resolves this issue immediately. Another factor could be DNS resolution delays; adding UseDNS no to the configuration can speed up the handshake process.
How do I allow multiple users to connect via SSH?
By default, any user account on the Ubuntu system with a valid password or SSH key can connect. To restrict access, you can use the AllowUsers directive in sshd_config to specify a whitelist of usernames who are permitted to log in. This adds an extra layer of control over who can access the system remotely.
Is it safe to leave SSH running on a virtual machine?
It is safe if you follow best practices such as disabling root login, using key-based authentication, and keeping the software updated. Using a firewall to restrict access to specific IP addresses further enhances security. Avoid exposing the SSH port directly to the public internet without additional protective measures like fail2ban.
What happens if I forget my SSH key passphrase?
If you lose the passphrase for your private key, there is no way to recover it. You will need to generate a new key pair and update the authorized_keys file on the server. To avoid this, store your private keys in a secure password manager or use a hardware security key for added protection.