Changing SSH port in Ubuntu or Debian

SSH or Secure Command is a network protocol, that helps to connect and perform operation in the remote machine. You can connect to SSH with key or username and password.

Image courtesy

By default SSH uses port 22. You may need to change the ssh port for security security reasons such as to avoid targets from bots. You can change the default port by below steps.

  • Login to the server/remote machine
  • Open /etc/ssh/sshd_config
  • Locate the text: Port 22
  • Change the port which you want to set. Choose a port between 1024 and 65535.
  • Save the file and exit
  • Restart the ssh service: sudo systemctl restart sshd
  • Disconnect from the server
  • Now, connect to machine with specifying new port as SSH is not utilising default port. Use code as below to ssh into the machine.

Note: -p is used for ssh and -P is used for scp to specify the port

Start-up and tech enthusiast. I write about Tech, Devops and anything related.