Troubleshooting SSH Hangs in Kubuntu 24.04 and Ubuntu 24.01 on VirtualBox
In this article, we'll explore the common causes of SSH hangs when running Kubuntu 24.04 and Ubuntu 24.01 virtual machines on VirtualBox, and provide some solutions to resolve these issues.
Identifying the Problem
When trying to connect to an Amazon EC2 instance or another remote server using SSH from a Kubuntu 24.04 or Ubuntu 24.01 virtual machine hosted on VirtualBox, the SSH client may hang or freeze. This can be frustrating, but the first step in resolving the issue is to identify the cause. There are several potential reasons why SSH might hang, including network issues, configuration problems, and resource limitations.
Checking Network Connectivity
The first step in troubleshooting SSH hangs is to check the network connectivity between the virtual machine and the remote server. You can use the ping command to test the connection:
ping <remote-server-ip-address>
If the ping command fails or times out, there may be a network issue preventing the connection from being established. In this case, you should check the network settings on both the virtual machine and the remote server to ensure that they are configured correctly.
Checking SSH Configuration
If the network connection is working properly, the next step is to check the SSH configuration on the virtual machine. There are several settings that can affect SSH performance and reliability, including the encryption algorithm, the maximum number of connections, and the maximum number of authentication attempts.
You can check the SSH configuration on the virtual machine by editing the /etc/ssh/sshd_config file. Here are some settings that you may want to check:
# MaxStartups: Sets the maximum number of concurrent unauthenticated connections to the SSH daemon.
# This value is in the format: number of connections, percentage of system resources, number of connections.
MaxStartups 10:30:100
# MaxSessions: Sets the maximum number of simultaneous sessions that may be established.
# This value must be at least 1.
MaxSessions 10
# LoginGraceTime: Sets the time limit for inactive sessions before they are disconnected.
# The default value is 120 seconds.
LoginGraceTime 120
# GSSAPIAuthentication: Enables GSSAPI authentication.
# The default value is no.
GSSAPIAuthentication yes
You can also check the SSH configuration on the remote server by editing the /etc/ssh/sshd_config file. Here are some settings that you may want to check:
# MaxStartups: Sets the maximum number of concurrent unauthenticated connections to the SSH daemon.
# This value is in the format: number of connections, percentage of system resources, number of connections.
MaxStartups 10:30:100
# MaxSessions: Sets the maximum number of simultaneous sessions that may be established.
# This value must be at least 1.
MaxSessions 10
# LoginGraceTime: Sets the time limit for inactive sessions before they are disconnected.
# The default value is 120 seconds.
LoginGraceTime 120
Checking Resource Limitations
If the SSH configuration is correct, the next step is to check for any resource limitations that may be causing the SSH client to hang. One potential issue is that the virtual machine does not have enough system resources to handle the SSH connection.
You can check the system resources on the virtual machine by running the top or htop command. Here is an example using top:
top
This will display a list of the processes running on the virtual machine, along with their resource usage. If the CPU usage is consistently high or the memory usage is close to the maximum, this may indicate that the virtual machine does not have enough resources to handle the SSH connection.
To resolve this issue, you may need to allocate more system resources to the virtual machine by increasing the amount of RAM or CPU cores assigned to it in VirtualBox.
Disabling Rekeying
Another potential cause of SSH hangs is the rekeying process, which is used to periodically refresh the encryption keys used to secure the connection. By default, SSH will rekey the connection every hour, but this can be adjusted using the ServerKeyBits and RekeyLimit settings in the SSH configuration file.
To disable rekeying completely, you can set the RekeyLimit value to no:
# RekeyLimit: Sets the maximum amount of data that may be transmitted before the session key is renegotiated.
# This value is in the format: bytes, seconds. The default value is 1G,1h.
# To disable rekeying, set this value to no.
RekeyLimit no
SSH hangs can be frustrating, but there are several potential causes and solutions. By following the steps outlined in this article, you should be able to identify and resolve the issue.
- Check network connectivity using the
pingcommand. - Check the SSH configuration on both the virtual machine and the remote server.
- Check for resource limitations on the virtual machine.
- Consider disabling rekeying to improve connection stability.
References
-
"man sshd\_config": https://man.openbsd.org/sshd\_config
-
"man ssh\_config": https://man.openbsd.org/ssh\_config
-
"SSH Port Forwarding": https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-port-forwarding-on-ubuntu-14-04