SSH (Secure Shell) is a popular protocol used for secure remote login and file transfer between computers. By default, SSH uses port 22 to establish connections. However, there may be situations where you need to change the SSH port for security reasons or to avoid conflicts with other services. In this article, we will discuss common issues that users may encounter when changing the SSH port in Almalinux9 and provide troubleshooting steps to resolve them.
Issue: Unable to Connect to SSH After Changing the Port
If you are unable to establish an SSH connection to your Almalinux9 server after changing the SSH port, there are a few potential causes and solutions to consider:
1. Check Firewall Settings
The first thing to check is your firewall settings. If you have a firewall enabled on your server, you need to allow incoming connections on the new SSH port. To do this, you can use the following command:
sudo firewall-cmd --permanent --add-port=/tcp
Make sure to replace <new_ssh_port> with the actual port number you have chosen. After running the command, reload the firewall rules:
sudo firewall-cmd --reload
Now try connecting to your server using the new SSH port.
2. Verify SSH Service Configuration
It is also important to ensure that the SSH service is configured to listen on the new port. Open the SSH server configuration file using a text editor:
sudo nano /etc/ssh/sshd_config
Look for the line that specifies the SSH port (usually Port 22) and change it to the new port number you have chosen. Save the file and exit the editor.
Restart the SSH service for the changes to take effect:
sudo systemctl restart sshd
Now try connecting to your server using the new SSH port.
3. Check SELinux Configuration
If you have SELinux enabled on your Almalinux9 server, it may be preventing SSH connections on the new port. You can check the SELinux status by running the following command:
sudo sestatus
If SELinux is set to Enforcing or Permissive, you need to allow SSH connections on the new port. Use the following command to add the new port to the SELinux policy:
sudo semanage port -a -t ssh_port_t -p tcp
Replace <new_ssh_port> with the actual port number you have chosen. After running the command, try connecting to your server using the new SSH port.
Issue: SSH Connection Times Out After Changing the Port
If your SSH connection times out after changing the port, there are a few possible causes and solutions to consider:
1. Check Network Configuration
Ensure that your server's network configuration allows incoming connections on the new SSH port. If you are using a router or firewall, make sure to forward the new port to your server's internal IP address.
2. Check SSH Client Configuration
If you are connecting from a remote machine, make sure that your SSH client is configured to use the correct port. Most SSH clients allow you to specify the port number using the -p option:
ssh -p user@server_ip
Replace <new_ssh_port> with the actual port number you have chosen and user@server_ip with your server's username and IP address.
3. Verify SSH Service Status
Check the status of the SSH service on your Almalinux9 server to ensure that it is running:
sudo systemctl status sshd
If the service is not active, start it using the following command:
sudo systemctl start sshd
Now try connecting to your server using the new SSH port.
By following the troubleshooting steps outlined above, you should be able to resolve common issues encountered when changing the SSH port in Almalinux9. Remember to always double-check your configuration and ensure that you have made the necessary changes in both the firewall and SSH service settings.
References
| Source | Link |
|---|---|
| Almalinux9 Documentation | https://almalinux.org/ |
| Red Hat Documentation | https://access.redhat.com/documentation |
| Firewalld Documentation | https://firewalld.org/documentation |