This is to edit the configuration file for the ssh server hosted on most vps solutions and used for general server management. 

On Ubuntu you will need to edit two files. Do not restart ssh services until every step is completed.

 

1- Edit the ssh config file

  • nano /etc/ssh/sshd_config
    • alter the following lines to your desired configurations or alter them to the ones below. You may also need to remove the # symbol for the configuration to take affect.
      • Port 1022
      • AllowRootLogin no
      • remove # from line for AuthorizedKeysFile
      • PasswordAuthentication no
      • PermitEmptyPasswords no
    • save and close the file (ctrl +x, press y then enter)
  • nano /etc/ssh/sshd_config.d/50-cloud-init.conf
    • edit the PasswordAuthentication from yes to no
      • save and close the file (ctrl +x, press y then enter)

 

2- Update the firewall rules

  • See directions in Article UFW For Ubuntu for directions to match your port number change in the configuration above and allow it via ufw.

 

3- Restart the SSH Service or Reboot the Server (Dealers Choice)

  • to restart the service run
    • service sshd restart
  • or to reboot run
    • sudo reboot -n