VirtualBox中两台Ubuntu服务器通信及SSH连接故障求助
Alright, let’s work through this SSH issue step by step—since you’ve confirmed the servers can ping each other, we know the core network layer is working. That narrows things down to SSH-specific settings or firewall rules. Here’s what to check:
1. Confirm the SSH Service is Active
First, make sure the SSH daemon is running on both servers. On Ubuntu, run this to check status:
systemctl status sshd
If you see "inactive (dead)" in the output, start the service right away:
sudo systemctl start sshd
And set it to launch automatically on boot so you don’t have to repeat this later:
sudo systemctl enable sshd
2. Check Ubuntu’s Default Firewall (UFW)
Ubuntu uses UFW by default, and it might be blocking incoming SSH connections (port 22). Verify the current rules with:
sudo ufw status
If you don’t see a line allowing ssh or 22/tcp, add the rule:
sudo ufw allow ssh # Or explicitly by port: sudo ufw allow 22/tcp
Then reload the firewall to apply changes:
sudo ufw reload
3. Inspect the SSH Configuration File
Sometimes SSH is configured to block certain connection types (like password login if you haven’t set up SSH keys yet). Open the config file with your preferred editor:
sudo nano /etc/ssh/sshd_config
Look for these critical settings and adjust them as needed:
PasswordAuthentication: Set toyesif you’re using a password to connect (switch back tonoonce you set up SSH keys for better security).PermitRootLogin: If you’re trying to connect as root, set this toyes(orprohibit-passwordif using SSH keys).ListenAddress: Ensure it’s set to0.0.0.0(listens on all network interfaces) or the server’s static IP address.
After making changes, restart the SSH service to apply them:
sudo systemctl restart sshd
4. Debug the Connection with Verbose Output
If the above steps don’t resolve the issue, run the SSH command with verbose mode to get detailed error messages—this will pinpoint exactly where the connection fails:
ssh -v your_username@192.168.1.111
Look for clues like "Connection refused" (points to service/firewall issues) or "Permission denied" (points to config or credential problems).
Quick VirtualBox Quirk Check
Even though ping works, double-check that your VirtualBox bridge adapter is attached to the correct physical network interface on your host machine (e.g., your active Wi-Fi or Ethernet adapter). You can confirm this in the VM’s settings > Network > Bridge Adapter > Name dropdown.
内容的提问来源于stack exchange,提问作者Dylan_

