To establish a direct Ethernet connection between two Ubuntu 22.04 PCs for SSH, assign static IPv4 addresses to both machines on the same subnet, ensure the OpenSSH server is active on the host, and connect via the client using the standard ssh command with the target IP address. This method bypasses routers and DHCP servers, creating a local link that requires no external network infrastructure.
Physical Connection and Interface Identification
Begin by connecting the two computers using a standard Cat5e or Cat6 Ethernet cable. Modern network interface cards (NICs) support Auto-MDIX, which automatically detects and corrects crossover requirements, so a standard straight-through cable works for almost all modern hardware without needing a specialized crossover cable. Once physically connected, identify the network interface names on both systems using theip addr show command. Look for interfaces that are not lo (loopback) and typically start with en (for Ethernet) or eth. Note these names, as they will be used in the configuration steps below. It is common for one interface to be named enp3s0 on one machine and enp0s31f6 on another; do not assume they share the same name.
Configuring Static IP Addresses
Since there is no DHCP server present on a direct cable link, you must manually assign IP addresses to both machines. Using NetworkManager, which is the default networking tool in Ubuntu 22.04, you can create a new connection profile for the specific interface. On the machine acting as the SSH server, open a terminal and runnmtui (Network Manager Text User Interface). Select "Edit a connection," choose your Ethernet interface, and modify it. Set the IPv4 Configuration to "Manual." Assign an IP address such as 192.168.1.10 and a netmask of 255.255.255.0 (/24 prefix). Save the connection and bring it down and up again to apply changes.
Repeat this process on the second machine, which will act as the SSH client. Configure the same interface with a manual IPv4 setting, but use a different IP address in the same subnet, such as 192.168.1.20, with the identical netmask 255.255.255.0. Do not set a gateway for either machine since they are communicating directly. After configuring both IPs, verify connectivity by pinging from one machine to the other. Run ping 192.168.1.20 from the first machine. If you receive replies, the physical layer and IP configuration are correct. If the ping fails, check the interface status with ip link to ensure the state is UP rather than DOWN.
Enabling the SSH Server
Ubuntu Desktop editions do not always have the SSH server enabled by default, whereas Ubuntu Server editions enable it automatically. To check if the SSH service is running on the target machine, executesystemctl status sshd. If the service is inactive or not installed, install it using sudo apt update && sudo apt install openssh-server. Once installed, enable and start the service with sudo systemctl enable --now sshd. You should see output indicating that the service is active and running.
It is important to note that while some guides suggest modifying firewall rules extensively, UFW (Uncomplicated Firewall) on Ubuntu typically allows incoming SSH traffic if the rule exists. By default, UFW may block incoming connections. To allow SSH, run sudo ufw allow ssh. This command opens port 22 for incoming TCP connections. There is no need to configure outbound ICMP or complex routing tables for a direct link. Ensure that the firewall is enabled with sudo ufw enable if it was previously disabled, as leaving the firewall off is a security risk even on a local link.
Establishing the SSH Connection
With the server configured and the client having a valid IP, initiate the connection from the client machine. Open a terminal and typessh [email protected], replacing username with the actual user account name on the server machine. The first time you connect, you will see a message asking to verify the host's authenticity. Type yes to add the server’s key to your known hosts file. You will then be prompted for the password of the remote user. Enter the password carefully; characters will not appear on screen for security reasons. Upon successful authentication, you will see the remote shell prompt, confirming that the direct Ethernet SSH connection is working.
If you encounter a "Connection refused" error, verify that the SSH service is actually listening on port 22 using ss -tlnp | grep :22. If you get a "Permission denied" error, double-check the username and password. For enhanced security, consider setting up SSH keys to avoid password prompts in the future, though this is optional for basic access.
Troubleshooting Common Issues
If the connection still fails after verifying IPs and services, check the following areas. First, ensure that both machines are on the exact same subnet. A mismatch like192.168.1.x vs 192.168.2.x will prevent communication. Second, check for any active VPNs or virtual network adapters on the client machine that might intercept the traffic. Disable any non-essential virtual networks temporarily. Third, verify that the Ethernet interface is not set to "Automatic" in NetworkManager settings, which might attempt to grab a lease from a router if one becomes available later, potentially overwriting your static config. Finally, consult related resources for broader networking context, such as Connecting to Ubuntu using ssh over Ethernet, which covers similar foundational concepts for remote access.
Frequently Asked Questions
Do I need a crossover cable for this setup?
No, modern network interfaces support Auto-MDIX, which automatically adjusts the pinout for direct connections. A standard straight-through Ethernet cable is sufficient for connecting two Ubuntu 22.04 PCs directly.Why can't I ping the other computer after setting IPs?
Check if the firewall is blocking ICMP packets. While UFW usually allows SSH, it might drop pings if custom rules are active. Verify the interface is UP withip link and ensure no other network managers are interfering with the connection.
Is it safe to leave SSH open on a direct link?
Yes, a direct Ethernet link isolates the traffic from the public internet. However, always use strong passwords or SSH keys. Avoid logging in as root unless necessary, and keep the system updated to patch potential vulnerabilities.What if I forget the SSH password?
You cannot recover a forgotten Linux password remotely via SSH. You would need physical access to the server machine to reset the password using recovery mode or by booting from a live USB drive to modify the/etc/shadow file.