Change the SSH Port on Dedicated and VPS. Change the SSH Port in Linux?
Here's how to Change the SSH Port on Dedicated and VPS.
i. Changing the SSH port on a Linux system involves modifying the SSH daemon configuration file. Here are the steps to change the SSH port:
### 1. **Connect to the Server:**
- Connect to your Linux server using SSH with the current port. For example:
```bash
ssh username@your_server_ip
```
### 2. **Edit the SSH Configuration File:**
- Open the SSH daemon configuration file using a text editor. The location of the configuration file may vary, but it is commonly found at `/etc/ssh/sshd_config`. Use a text editor such as `nano` or `vi`. For example:
```bash
sudo nano /etc/ssh/sshd_config
```
### 3. **Locate the Port Configuration:**
- Look for the line that specifies the SSH port. The default is usually:
```conf
Port 22
```
Change the number (22) to your desired port number.
### 4. **Choose a New Port:**
- Choose a new port number between 1024 and 65535. Avoid using well-known ports or ports already assigned to other services.
### 5. **Save and Close the File:**
- Save the changes and close the text editor.
- For `nano`, press `Ctrl + X`, then press `Y` to confirm changes, and finally press `Enter`.
- For `vi`, press `Esc`, then type `:wq` and press `Enter`.
### 6. **Restart the SSH Service:**
- Restart the SSH service to apply the changes:
```bash
sudo service ssh restart
```
or
```bash
sudo systemctl restart ssh
```
### 7. **Verify the New Port:**
- Try to reconnect to the server using the new port:
```bash
ssh -p your_new_port username@your_server_ip
```
Replace `your_new_port` with the chosen port number.
### 8. **Update Firewall Rules:**
- If you have a firewall enabled, update its rules to allow traffic on the new SSH port. For example, if using `ufw`:
```bash
sudo ufw allow your_new_port
```
### Important Considerations:
- Ensure that the chosen port is not blocked by firewalls, and it is allowed by your hosting provider if applicable.
- Always choose a strong, unique port number to enhance security.
- Make sure you update your SSH client configuration if needed, especially if you are using tools like PuTTY.
Changing the SSH port is a security measure, but it's important to keep track of the new port to avoid connectivity issues.