List of content you will read in this article:
- 1. What is SSH? [Definition]
- 2. What is an SSH Port Number?
- 3. How does SSH work? [A Complete Guide]
- 4. Uses of SSH
- 5. What is Default SSH Port Number?
- 6. How to Change the Default SSH Port?
- 7. Conclusion
Today, secured communication is one of the biggest priorities for every organization, as major tasks are being done by transferring data from one device to another over the network. Thus various strategies are being implemented to ensure complete security to keep the integrity of the data while transferring. Some companies work on crucial data that need to be secured. Thus, they set rules for communicating with other devices over the internet. With this post, you will get a brief understanding of the SSH port number, the default SSH port, how to change and how it works.
SSH became an extension of the traditional telnet protocol. However, telnet was not that secure and thus replaced by ssh over time. If you are a system administrator, then you might have used ssh.
What is SSH? [Definition]
SSH is a network protocol to access the server remotely. It provides you with a secure way to comply with a device over any sort of unsecured network. It’s not just about the security services; it also refers to the bag of utilities that helps to implement the SSH protocol.
Features of SSH
There are ample features associated with SSH. Let’s dive in!
- It has strong password authentication, encrypted data communication, and public-key authentication.
- It manages systems and applications remotely and allows others to use another computer and perform several functions.
- It is a cryptographic network protocol and uses the client/server model
- You can create secure tunnels for different application protocols too. Application protocols are further used for terminal emulation or for transferring the files
Now it's time to understand the SSH port number.
What is an SSH Port Number?
Every communication done by ssh needs ports to connect and start the communication. Whether wired or wireless device, it will require an SSH port. More than 65k communication ports are available, and you can start communication using any of these ports. All communication is done by default port number, which can be changed and set to any other available port number. Whenever the user runs the Linux command to start the communication between the two devices over the network, the connection will use Default SSH port number 22.
But, if you are carrying out any crucial communication that requires safety, it is recommended that you change the default ssh port number to another to avoid a brute-force attack. Everyone knows that 22 is the default ssh port number and is most prone to attacks, and any hacker will easily hack your transferred data. Using an ssh port, you can implement the SSH protocol.
How does SSH work? [A Complete Guide]
The SSH protocol works in the client-server model, where one device is the server and the other acts as a client. The SSH client will establish the connection process and uses public-key cryptography to verify the identity of the SSH server. After the connection has been set up, the SSH protocol will use strong symmetric encryption and hashing algorithms to ensure the privacy and integrity of the data that is being transferred between the client and server.
The image below will show the server and client data flow.
In the process of working on the SSH protocol, we will be discussing various steps that take place.
- Establishing an SSH connection.
- Session encryption negotiation.
- User authentication.
Step 1: Establishing an SSH connection
To create an SSH connection, you need to run a command from the client’s machine, as shown below.
Once the command runs, a session encryption negotiation process will start.
Step 2: Session encryption negotiation
Once the request has been sent to the server, the server will send the client a set of encryption protocols being supported by the server. The server will then use the public key as the authentication method. The client will match the server’s set of protocols with its own. If the protocol matches, then both machines will agree to establish the connection and start the data transfer.
The client will compare the server's public key to the locally stored private key while establishing the connection for the first time. If both the keys match, the client and server will start the symmetric encryption method for communicating during the SSH session. For this communication to occur, they will start communicating using an asymmetrically encrypted process that works on the Diffie-Hellman (DH) key exchange algorithm for securely creating a cryptographic key over a public network. For generating a key, the machines will be performing the following steps:
- Both the machines will agree on two numbers which are a modulus and a base number. To prevent brute force key decryption, you must choose a modulus as a prime number of at least 600 digits.
- The machines will individually choose one number and apply it to the two public numbers equation.
- The server and the client will then exchange these calculated values.
- Each machine will perform a calculation based on the result received from the other, as shown below.
After the process, a shared secret key will be generated that will be shared between both devices.
Step 3: User authentication
The most commonly used SSH user authentication methods are passwords and SSH keys. The clients will send the encrypted passwords to the server securely. However, in some scenarios, the passwords are considered a risky authentication method as the password's strength depends on how the user creates the password.
While using the asymmetrically encrypted SSH public-private key pairs is considered a better option than passwords. Once the client decrypts the message, the server will then grant the required system access to the client.
To generate an SSH key pair, you must type ssh-keygen in the terminal. Then, the system will generate and store the keys, as shown below.
SSH was introduced to update the insecure terminal emulation, for instance, rlogin or Telnet. SSH performs the same functions with more flexibility and comfort. Not just this, but it also replaces several file transfer programs. For instance, File Transfer Protocol and Remote Copy.
The primary aim of SSH is to connect the remote host in case of a terminal session. You use the following command to achieve the task:
What does this Linux command do?
Well, this command will help the client to connect to the server.
Moving onto the next segment, SSH has various associated uses, which are listed below.
Uses of SSH
- By default, you will get the SSH terminal for MAC, Windows, and Unix system.
- Various kinds of communications can be secured with the help of SSH connections between a remote host and a local machine.
- It is also used to manage routers, virtualization platforms, server hardware, file transfer applications, and much more.
- You can also connect to servers and use tools or the terminal to upload and exit.
- SSH keys come with SSO, or single sign-on, that helps the users to move between the accounts without inserting the password every time
Additionally, it plays an important role in access management and identity management. The SSH traffic is highly encrypted as well. It also assists you with the secure issuance of commands on several remote devices. You can expect secured as well as automated file transfers. Also, be assured of the security management of your network infrastructure components.
In a nutshell, SSH is widely used in scripts and several other software to access data and resources remotely and securely. Now, let us incline our focus on our core topic, that is, the SSH default port.
What is Default SSH Port Number?
This Default SSH port number 22 is considered unsafe for crucial data transfers. Changing the default port number to another port is smart to avoid brute-force attacks. In total, there are 65,536 communication ports.
Now, Every connection initializes through this port. Besides, there are several instances where there is a need to change the default SSH port number for security purposes. Security measures become necessary to protect the server from brute force attacks.
When we talk about the brute force attack, it is an error method to crack the incorrect data. For instance, figuring out passwords via exhaustive efforts instead of algorithms. It means to hit and try until you crack the code. Additionally, as it is evident that Port 22 is the default communication port, it becomes easier for unauthorized parties to access data.
When you switch this port to another, the hacker has to try several other ports to find an open port ultimately. Therefore, to put any hacker out of bounds, this step can be taken.
But the question is, how to change the default SSH port?
How to Change the Default SSH Port?
1. To change default SSH port, you must edit the sshd_config file. Besides, keeping a backup of your file is always a good option. Use this command to create a backup first:
ubuntu@ubuntu:~$ cp /etc/ssh/sshd_config /etc/ssh/sshd_config_backup
This command creates a copy of the file in the same directory.
2. The next step is to change the default SSH port. Open the ssh_config file in any editor. Now, enter the following command:
ubuntu@ubuntu:~$ gedit /etc/ssh/sshd_config
3. After you execute this command, the mentioned file opens in the text editor. Search this line in the code:
4. Now, say you want to shift your port number to 45673. For that, remove the hash (#) sign and insert the desired port number instead of 22. Take a look:
5. Besides, do not forget to whitelist this port on your firewall to avoid locking yourself from your device.
Moving on, it’s time to restart SSH.
6. To restart the server to load the changes, you must follow this command as given below:
ubuntu@ubuntu:~$ sudo service sshd restart
As soon as you restart your device, you can see the changes that you made. Keep in your mind the most important security configuration is changing the default ssh port number just after you Purchase Linux VPS.
You can easily test the changes without logging out of your SSH session.
How to Test the Changes?
After you successfully change the default port, you must mention the port number to establish a connection with the server. Here is the command that you need to execute:
ubuntu@ubuntu:~$ ssh username@userIP -p 45673
You set your port number as 45673.
Therefore, you can see that the process is extremely easy and simple. You need to execute a few commands and are good to go.
This secure shell network is the commonly used process to secure the connection between devices over the network. Many companies have implemented SSH protocols to ensure complete data transfer safety. The default SSH port number is 22. Still, it becomes risky in many scenarios where you need to transfer crucial data. You need to change the SSH port number to prevent a brute-force attack.
In this article, we have mentioned various features and working of SSH Port Number, and It’s working. Using this guide, you can change the Default SSH port number per your requirement.
People are also reading: