How do I change my Droplet's SSH port?

You can change your Droplet’s default SSH port by editing its SSH configuration file. To do this, open the /etc/ssh/sshd_config file in a text editor:

nano /etc/ssh/sshd_config

Remove the comment hash (#) in the # Port 22 line and then replace the 22 value with your desired port value. In the following example, the Port line is uncommented and the 22 value is replaced with 20202. This makes the Droplet only accessible via SSH using port 20202.

    
        
            
# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Include /etc/ssh/sshd_config.d/*.conf

Port 20202
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

        
    

After editing the port number, save the file and close it. To implement the changes, reboot the Droplet:

reboot

Once the Droplet reboots, you can confirm the changes by logging in to the Droplet using the ssh command line tool and its port (-p) flag. Use the -p flag to specify the Droplet’s new SSH port:

ssh root@<your_droplet_IP_address> -p <new_port_number>

For example, if your Droplet has the IP address 192.88.99.255 and the Droplet’s new SSH port is 20202, you would format the command like this:

ssh root@192.88.99.255 -p 20202

A successful login to the Droplet confirms that SSH port has been successfully reassigned. If your login was unsuccessful, you can log in to the Droplet from the Droplet Console and troubleshoot the configuration file.

All Droplets are assigned IPs that are owned by DigitalOcean, which is headquartered in the US.
Older Droplets that did not have VPC enabled prior to October 2020 cannot be added to a VPC network without changing its IP address.
You cannot retain a Droplet’s IPv4 when you transfer the Droplet to a new region. Use a reserved IP address to maintain a static IP address.